diff --git a/DataCenter_Windows/DBTestData/flexitimedb.db b/DataCenter_Windows/DBTestData/flexitimedb.db new file mode 100644 index 0000000..4ba81b3 Binary files /dev/null and b/DataCenter_Windows/DBTestData/flexitimedb.db differ diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs index b9e3214..406824e 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/User.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace Interfaces { @@ -19,7 +20,7 @@ namespace Interfaces { get { return AssociatedIdentifiers.Count; } } - + public DateTime LastEventDateTime { get; set; } public List AssociatedIdentifiers { get; set; } public bool State { get; set; } diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index d39734c..dfbcb91 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -67,26 +67,15 @@ namespace SQLiteRepository foreach (var user in users) { var userObj = ChangeToUserObject(user); - var cards = _connection.Query( - SQLiteProcedures.GET_CARDS_BY_USER_ID, - user.Id); - foreach (var card in cards) - { - userObj.AssociatedIdentifiers.Add(new Identifier() - { - UniqueId = card.CardUId, - IsAssociatedToUser = true, - Id = card.Id - }); - } + userObj.AssociatedIdentifiers = GetAssociatedIdentifiers(user.Id); userObj.State = GetUserState(GetLogDirection(user.Id)); - + userObj.LastEventDateTime = GetLastLogDateTime(GetLastTimeLog(user.Id)); ret.Users.Add(userObj); } if (pageNumber == -1 && pageSize == -1) { - ret.PageSize = 1; //TODO: switch to ret.UserCount + ret.PageSize = 10; ret.PageNumber = 1; } else @@ -98,6 +87,15 @@ namespace SQLiteRepository return ret; } + private DateTime GetLastLogDateTime(TimeLogDb timeLog) + { + if (timeLog != null) + { + return timeLog.SwipeEventDateTime.DateTime; + } + return DateTime.MinValue; + } + private bool GetUserState(LogDirectionDb logDirection) { switch (logDirection) @@ -142,6 +140,7 @@ namespace SQLiteRepository Id = card.Id }); } + userObj.State = GetUserState(GetLogDirection(user.Id)); ret.Users.Add(userObj); } //TODO: figure out paging here. - should there be any? @@ -186,7 +185,7 @@ namespace SQLiteRepository return ret; } - //TODO: refac this as it duplicates a lot of code. + public TimeLogList GetTimeLogs(int userId) { return GetTimeLogs(userId, DateTime.UtcNow); @@ -503,23 +502,20 @@ namespace SQLiteRepository var logDirection = LogDirectionDb.UNKNOWN; if (userId != -1) { - var lastEntry = _connection.Query( - SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION, - userId); - if (lastEntry.Any()) + var lastEntry = GetLastTimeLog(userId); + if (lastEntry != null) { - var lastLog = lastEntry.First(); // See if the datetime retrieved is yesterday. If yesterday, logDirection = true (in) - if (IsLogDateTimeYesterdayOrOlder(lastLog.SwipeEventDateTime.DateTime)) + if (IsLogDateTimeYesterdayOrOlder(lastEntry.SwipeEventDateTime.DateTime)) { logDirection = LogDirectionDb.IN; } else { // we have a time log from today already, so just do the opposite of what we last did! - if (lastLog.Direction == LogDirectionDb.IN) + if (lastEntry.Direction == LogDirectionDb.IN) logDirection = LogDirectionDb.OUT; - else if (lastLog.Direction == LogDirectionDb.OUT) + else if (lastEntry.Direction == LogDirectionDb.OUT) logDirection = LogDirectionDb.IN; } } @@ -532,6 +528,36 @@ namespace SQLiteRepository return logDirection; } + private TimeLogDb GetLastTimeLog(int userId) + { + var lastEntry = _connection.Query( + SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION, + userId); + if (lastEntry.Any()) + { + return lastEntry.First(); + } + return null; + } + + private List GetAssociatedIdentifiers(int userId) + { + var cards = _connection.Query( + SQLiteProcedures.GET_CARDS_BY_USER_ID, + userId); + var ret = new List(); + foreach (var card in cards) + { + ret.Add(new Identifier() + { + UniqueId = card.CardUId, + IsAssociatedToUser = true, + Id = card.Id + }); + } + return ret; + } + /// /// Get the calendar week of the year according to the ISO8601 standard (starts monday). /// diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html index 5948257..124156b 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html @@ -76,10 +76,10 @@ - IN + IN - OUT + OUT diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js index 37bed76..93973f6 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js @@ -142,7 +142,7 @@ }; self.convertToDisplayTime = function (dateValue) { var date = new Date(dateValue); - return date.getHours() + ":" + (date.getMinutes() < 10 ? '0' : '') + date.getMinutes(); + return date.getHours() + ":" + self.padNumber(date.getMinutes()); }; self.correctLogOffset = function (logCount) { if (logCount % 2 !== 0) { @@ -156,6 +156,18 @@ self.getTimeLogEntryArrayLength = function(maxDailyLogs) { return Math.round(maxDailyLogs/2); }; + self.padNumber = function(number) { + return (number < 10 ? '0' : '') + number; + } + self.convertToDisplayDateTime = function (dateValue) { + var date = new Date(dateValue); // dd MM YY HH:mm:ss e.g.: 01 Mar 17 17:34:02 + return date.getDay() + " " + + date.toLocaleString("en-us", { month: "long" }) + " " + + (date.getYear()-100) + " " + + self.padNumber(date.getHours()) + ":" + + self.padNumber(date.getMinutes()) + ":" + + self.padNumber(date.getSeconds()); + }; self.dismissAlert = function(data, event) { self.errorData(null); }; @@ -229,6 +241,7 @@ var url = self.createRequestUrl(self.apiEndpoints.getUserList, args, false); $.getJSON(url, function (res) { self.userList(res); + $('[data-toggle="tooltip"]').tooltip(); }).fail(function (response, status, error) { console.log("error - getusers"); var errObj = self.processRequestFailure(response, status, error); diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj index 8b8049d..e5f50d5 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataServiceHost/WindowsDataServiceHost.csproj @@ -76,7 +76,9 @@ - + + Designer +