From 8d7b027b8c2f13f5dd36d73359c5393415b94400 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 16 Apr 2017 19:35:20 +0100 Subject: [PATCH 1/5] remove spa.min.* files. --- .gitignore | 1 + .../WindowsDataCenter/WindowsDataCenter/www/spa.min.css | 1 - .../WindowsDataCenter/WindowsDataCenter/www/spa.min.js | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) delete mode 100644 DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.css delete mode 100644 DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.js diff --git a/.gitignore b/.gitignore index 97a2c2b..0930bf1 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ **csproj.DotSettings **.csproj.user *spa.min.* +**spa.min.* diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.css b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.css deleted file mode 100644 index 69d4616..0000000 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.css +++ /dev/null @@ -1 +0,0 @@ -.table td.fit,.table th.fit{white-space:nowrap;width:1%}.table>tbody>tr>td.valign{vertical-align:middle}@media(max-width:576px){ul>li>a.indent-nav-xs{padding-left:50px}}.bootstrap-datetimepicker-widget tr:hover{background-color:#808080}.datepicker tr.highlight{background:#eee;cursor:pointer}.footer{position:absolute;bottom:0;width:100%;height:132px}.footerBody{margin-bottom:132px} \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.js b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.js deleted file mode 100644 index 47caf59..0000000 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.min.js +++ /dev/null @@ -1 +0,0 @@ -function DataVM(){"use strict";var n=this;n.menuOptions=["Home"];n.chosenMenuItemId=ko.observable();n.appDetails=ko.observable(null);n.userList=ko.observable(null);n.groupsList=ko.observable(null);n.chosenUserDetails=ko.observable(null);n.userTimeLogData=ko.observable(null);n.unassignedCardData=ko.observable(null);n.chosenTimeLogUserId=-1;n.selectedCalendarWeek=ko.observable(0);n.errorData=ko.observable(null);n.apiEndpoints={root:"http://localhost:8800",getUserList:"/api/users",getUserDetails:"/api/users",editUser:"/api/users/edit",getTimeLogs:"/api/timelogs",getUnassignedCards:"/api/cards/unassigned",getGroups:"/api/groups",getAppDetails:"/api/app"};n.uiPages={users:"users",userDetails:"userData",timeLogs:"timelogs",home:function(){return this.users}};n.goToMenuOption=function(n){location.hash=n;console.log("goToMenuOption: "+n)};n.goToUserDetails=function(t){location.hash=n.uiPages.userDetails+"/"+t.UserId};n.goToTimeLogs=function(t,i,r){var f,u;f=t.UserId?t.UserId:t;u="timelogs/"+f;r&&(u=n.createRequestUrl(u,r,!1,!1));location.hash=u};n.assignErrorObject=function(t,i,r){var u={errorCode:t,errorMessage:i,errorSource:r,errorDate:(new Date).toDateString("yyyy-mm-dd")};n.errorData(u)};n.processRequestFailure=function(n){return n.readyState===4?{errorCode:n.status,errorMessage:n.statusText,errorSource:""}:n.readyState===0?{errorCode:n.status,errorMessage:"Network Error - Is the server available?",errorSource:""}:{errorCode:n.status,errorMessage:"Unknown Error",errorSource:""}};n.createRequestUrl=function(t,i,r,u){var o="?",f="",e;if(u&&(f=n.apiEndpoints.root),f=f+t,i!==undefined&&i!==null&&i.length>0)for(e=0;e0?n.getUserList(null,null,t):n.getUserList(r,u)});this.get("#userData/:userId",function(){n.chosenMenuItemId("Data");n.userList(null);n.getUserDetails(this.params.userId);n.userTimeLogData(null);n.getUnassignedCardData()});this.get("#timelogs/:userId",function(){var t=this.params.selectedDate;n.chosenMenuItemId("Other");n.userList(null);n.chosenUserDetails(null);n.chosenTimeLogUserId=this.params.userId;n.getTimeLogData(this.params.userId,t)});this.get("#newUser",function(){n.chosenMenuItemId("newUser");n.userList(null);n.userTimeLogData(null);n.chosenUserDetails({UserId:-1,FirstName:null,LastName:null,HoursPerWeek:null,AssociatedIdentifiers:[],Groups:[],IsContractor:!1});n.getGroups(function(t){n.chosenUserDetails().Groups=t;n.chosenUserDetails.valueHasMutated()});n.getUnassignedCardData()});this.get("#stats",function(){n.goToMenuOption("users")});this.post("#edituser",function(){return $.each(n.chosenUserDetails().AssociatedIdentifiers,function(t,i){i.IsAssociatedToUser!==!0&&n.chosenUserDetails().AssociatedIdentifiers.splice(t,1)}),$.each(n.unassignedCardData().data,function(t,i){i.IsAssociatedToUser===!0&&n.chosenUserDetails().AssociatedIdentifiers.push(i)}),n.submitChangedUser(n.chosenUserDetails()),!1});this.get("",function(){this.app.runRoute("get","#"+n.uiPages.home())})}).run()}ko.applyBindings(new DataVM);$(document).on("mouseenter",".datepicker-days tbody tr",function(){$(this).addClass("highlight")});$(document).on("mouseleave",".datepicker-days tbody tr",function(){$(this).removeClass("highlight")}) \ No newline at end of file From d50331fc041cd74679b7dd0aacb97f81784a822b Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 16 Apr 2017 19:39:13 +0100 Subject: [PATCH 2/5] create EventLogResponse to hold the direction of the user and the operational response. #17 --- .../Interfaces/EventLogResponse.cs | 14 ++++++++++++++ .../WindowsDataCenter/Interfaces/Interfaces.csproj | 1 + 2 files changed, 15 insertions(+) create mode 100644 DataCenter_Windows/WindowsDataCenter/Interfaces/EventLogResponse.cs diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/EventLogResponse.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/EventLogResponse.cs new file mode 100644 index 0000000..8331d70 --- /dev/null +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/EventLogResponse.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Interfaces +{ + public class LogEventResponse + { + public LogDirection Direction { get; set; } + public OperationResponse ProcessResponse { get; set; } + } +} diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj b/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj index 70f72cc..2a53dee 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/Interfaces.csproj @@ -60,6 +60,7 @@ + From 094afc290319dc6aa6b9f53fe12e0000e8fcfda1 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 16 Apr 2017 19:39:51 +0100 Subject: [PATCH 3/5] change the interface to return a LogEventResponse object #17 --- DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs index bdd3acf..30f8141 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs @@ -95,7 +95,7 @@ namespace Interfaces /// /// to indicate procedure status. /// - OperationResponse LogEventTime(Identifier identifier, out int logId); + LogEventResponse LogEventTime(Identifier identifier, out int logId); OperationResponse CreateGroup(Group group, out int groupId); List GetGroups(int userId = -1); From c92ed064fccf5a71d0f73c77537aabdcc6a99ec9 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 16 Apr 2017 19:40:33 +0100 Subject: [PATCH 4/5] move private methods to end of class. change LogEventTime implementation to return a LogEventResponse object. #17 --- .../SQLiteRepository/SQLiteRepository.cs | 58 ++++++++++--------- 1 file changed, 32 insertions(+), 26 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index 3e2d97d..1d29754 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -98,27 +98,7 @@ namespace SQLiteRepository ret.TotalUserCount = userCount; return ret; } - - private DateTime GetLastLogDateTime(TimeLogDb timeLog) - { - if (timeLog != null) - { - return timeLog.SwipeEventDateTime.DateTime; - } - return DateTime.MinValue; - } - - private bool GetUserState(LogDirectionDb logDirection) - { - switch (logDirection) - { - case LogDirectionDb.OUT: - return true; - default: - return false; - } - } - + public UserList Search(string searchParam) { _logger.Trace("Searching SQLite database for the term: {0}", searchParam); @@ -361,8 +341,9 @@ namespace SQLiteRepository return ret; } - public OperationResponse LogEventTime(Identifier identifier, out int logId) + public LogEventResponse LogEventTime(Identifier identifier, out int logId) { + var ret = new LogEventResponse(); var cardIdQuery = _connection.Query( SQLiteProcedures.GET_CARDS_BY_UNIQUE_ID, identifier.UniqueId); @@ -378,7 +359,9 @@ namespace SQLiteRepository UpdateIdentifierLastUsed(DateTimeOffset.UtcNow, ident.Id); logId = -1; //dont try to log any timelogs against this card, as it is unassigned to a user. - return OperationResponse.SUCCESS; + ret.ProcessResponse=OperationResponse.SUCCESS; + ret.Direction = LogDirection.UNKNOWN; + return ret; } else { @@ -404,7 +387,9 @@ namespace SQLiteRepository { _logger.Error("Not logging event for user id: {0}, logged event within TimeGap Threshold of {1}", ident.UserId_FK, threshold); logId = -1; - return OperationResponse.FAILED; + ret.ProcessResponse = OperationResponse.FAILED; + ret.Direction = LogDirection.UNKNOWN; + return ret; } } @@ -431,8 +416,9 @@ namespace SQLiteRepository UpdateIdentifierLastUsed(timeLog.SwipeEventDateTime, timeLog.IdentifierId); logId = timeLog.Id; - - return OperationResponse.SUCCESS; + ret.Direction = (LogDirection)(int)logDirection; + ret.ProcessResponse = OperationResponse.SUCCESS; + return ret; } /*Groups*/ @@ -565,6 +551,26 @@ namespace SQLiteRepository return OperationResponse.UPDATED; } + private DateTime GetLastLogDateTime(TimeLogDb timeLog) + { + if (timeLog != null) + { + return timeLog.SwipeEventDateTime.DateTime; + } + return DateTime.MinValue; + } + + private bool GetUserState(LogDirectionDb logDirection) + { + switch (logDirection) + { + case LogDirectionDb.OUT: + return true; + default: + return false; + } + } + private int ConvertSourceToIdentifierId(LogSource logSource) { switch (logSource) From 3446dda71073c805c8d27814335169ebc4862c00 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Sun, 16 Apr 2017 19:41:31 +0100 Subject: [PATCH 5/5] changed api method to use the return type of IRepository.LogEventTime method and return the Id and Direction from the endpoint. #17 --- .../Controllers/SwipeDataController.cs | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs index a1b8a9d..ed31a9f 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/SwipeDataController.cs @@ -14,10 +14,12 @@ namespace WindowsDataCenter { private readonly IRepository _repo; private readonly ILogger _logger; + /// /// /// /// + /// public SwipeDataController(IRepository repo, ILogger logger) { if(repo == null) throw new ArgumentNullException(nameof(repo)); @@ -36,13 +38,10 @@ namespace WindowsDataCenter public IHttpActionResult PostData([FromBody] CardData cData) { int logId; - _repo.LogEventTime(new Identifier {UniqueId = cData.CardUId}, out logId); - _logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}", cData.CardUId, DateTime.UtcNow); - return - ResponseMessage(new HttpResponseMessage(HttpStatusCode.OK) - { - Content = new StringContent(logId.ToString()) - }); + var resp = _repo.LogEventTime(new Identifier {UniqueId = cData.CardUId}, out logId); + _logger.Trace("Received new \"Swipe Event\" for UId: {0} at {1}, direction is : {2}", cData.CardUId, + DateTime.UtcNow, resp.Direction); + return Ok(new {Id = logId, resp.Direction}); } } } \ No newline at end of file