From 309e8c093d34debedf9b62d818f22baaccf846a5 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Fri, 3 Mar 2017 12:57:52 +0000 Subject: [PATCH 1/5] added sqlite test data db --- DataCenter_Windows/DBTestData/flexitimedb.db | Bin 0 -> 20480 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 DataCenter_Windows/DBTestData/flexitimedb.db diff --git a/DataCenter_Windows/DBTestData/flexitimedb.db b/DataCenter_Windows/DBTestData/flexitimedb.db new file mode 100644 index 0000000000000000000000000000000000000000..4ba81b3d7af78bea8029a3a0511102200743bd79 GIT binary patch literal 20480 zcmeI4Z)_7~9LMi^?bglSJ(#vD1z|^_x;bDS&{32b`WGjIARFLVV|!bVanN12>vdz} zPco4ghz^t(B_YOyNCaM>l7NYcAq0qVKm@_)8wFl~glIG-N{j@bU!n9m@eSD<&F_+? z&wZco^L>85&)u8Lu4{dFx~Hbn)12~%imJ=qvL^OwN{^%siW}rX zQOfBVMeWk$9$D2zHA6qSbXuHQ=~dT}a*(3H#TGu*BgQ{DkhltN-a$0t|e7}{o=?s0!1zg#1 zM%6W`OV1b^T5c+H)zz`>`F65>Y5HiK$jW^=S?!X?oN^^ijhU=bX>l{@%G%*6Y#!0@ zmV9Pd(o!o`g(fzqjAK(t8odBT+oK_R_+66Eg&U-RtrnimEo6ux*U2dPh`ddQcpw2J zfCP{L5P z{R_*zzyI%H$WP=F`J5aid&aFe3_=1(00|%gB!C2v01`j~NB{{S0VIF~9ztNUrHpY+ zDR<<*SZh$yGV0Q?DX-mJ#<<Ec@@8c}ByI5;@ou*`0OS+!*!t;NfEyR#p5bU!_CBgs1;7ld#RB@y-$xPw2$^pTk+!{ARlgbJMv$%4ewSuT+kyx7e@bP$zgUNq zJ>C8FVk$c388=LS|K6%Ez&h7pU2<(S(hAl&M(g5VYApn;4F>BX`%CIkDms0I!t#9t z&W|?Tq;ge#p%1f}_K_U@CNkUv`s{+vaiE{vJAVmFb;m5jj>(g|HdThGYM)u$F}Xju zb@WxR))}q)hWf5NM^)$3g*xCuB{!bh9X}0nZ9#?$mE5S?K9(T3#t__p;kT(t@IF=W zLMzGM?K_z>AU|o86URPSb-@p^w;)4u;>dxHcV|)AF~d+@q9IpvD}VW>gE@blz&z<9 z`}%dr@RZ6I4i5fBW&5;Zb&0COCxS;HSTqJZ?jGO$D_E52 zd`JD7{t+rV+{WO?7P`Ov6RZ;r*7A9~&TOHg(`CKC8$j;3YjVE!6(m#{5<2dj+Z0(3 i3C?0d$N7lqvmvlLjMlS5`_q@fYByLh literal 0 HcmV?d00001 From 69f3e502e031238c91e1a73cbdc801c564f190f1 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Fri, 3 Mar 2017 13:00:01 +0000 Subject: [PATCH 2/5] Add LastEventDateTime property to User object Add Code to populate the LastEventDateTime property in SQLiteRepository - getting the last TimeLogEvent datetime. will return min value if no logs available. #53 --- .../WindowsDataCenter/Interfaces/User.cs | 5 +-- .../SQLiteRepository/SQLiteRepository.cs | 32 ++++++++++++++----- 2 files changed, 27 insertions(+), 10 deletions(-) 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..5840581 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -98,6 +98,14 @@ 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) @@ -503,23 +511,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 +537,17 @@ 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; + } /// /// Get the calendar week of the year according to the ISO8601 standard (starts monday). /// From 7110e3e2fea2d5f53e1413f28ed76b9551b206f4 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Fri, 3 Mar 2017 13:00:49 +0000 Subject: [PATCH 3/5] add data bound tooltip to show the last event date time when hovering over the In/Out indicator #53 --- .../WindowsDataCenter/WindowsDataCenter/www/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html index 5948257..97beaae 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 From b0b1fd45760f1c6cfa3931bb6815a0480fd0e066 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Fri, 3 Mar 2017 13:01:31 +0000 Subject: [PATCH 4/5] Refactor code to simplify methods. --- .../SQLiteRepository/SQLiteRepository.cs | 40 ++++++++++++------- .../WindowsDataServiceHost.csproj | 4 +- 2 files changed, 28 insertions(+), 16 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index 5840581..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 @@ -106,6 +95,7 @@ namespace SQLiteRepository } return DateTime.MinValue; } + private bool GetUserState(LogDirectionDb logDirection) { switch (logDirection) @@ -150,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? @@ -194,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); @@ -548,6 +539,25 @@ namespace SQLiteRepository } 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/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 + From 50e9d3d1823ee7aa8ce82083a7d3525863aca6f5 Mon Sep 17 00:00:00 2001 From: "chris.watts90@outlook.com" Date: Fri, 3 Mar 2017 20:48:12 +0000 Subject: [PATCH 5/5] correct data binding for LastEventDateTime property added method to convert the datetime to a display format. created padNumber to ensure numbers below 10 get shown as two digits. #53 --- .../WindowsDataCenter/www/index.html | 4 ++-- .../WindowsDataCenter/www/spa.js | 15 ++++++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/index.html index 97beaae..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);