Merge branch 'ShowLastEventDateTime-#53' into Release0.1.5
This commit is contained in:
commit
168154a561
BIN
DataCenter_Windows/DBTestData/flexitimedb.db
Normal file
BIN
DataCenter_Windows/DBTestData/flexitimedb.db
Normal file
Binary file not shown.
@ -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<Identifier> AssociatedIdentifiers { get; set; }
|
||||
|
||||
public bool State { get; set; }
|
||||
|
||||
@ -67,26 +67,15 @@ namespace SQLiteRepository
|
||||
foreach (var user in users)
|
||||
{
|
||||
var userObj = ChangeToUserObject(user);
|
||||
var cards = _connection.Query<CardUniqueId>(
|
||||
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<TimeLogDb>(
|
||||
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<TimeLogDb>(
|
||||
SQLiteProcedures.GET_LAST_TIMELOG_DIRECTION,
|
||||
userId);
|
||||
if (lastEntry.Any())
|
||||
{
|
||||
return lastEntry.First();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private List<Identifier> GetAssociatedIdentifiers(int userId)
|
||||
{
|
||||
var cards = _connection.Query<CardUniqueId>(
|
||||
SQLiteProcedures.GET_CARDS_BY_USER_ID,
|
||||
userId);
|
||||
var ret = new List<Identifier>();
|
||||
foreach (var card in cards)
|
||||
{
|
||||
ret.Add(new Identifier()
|
||||
{
|
||||
UniqueId = card.CardUId,
|
||||
IsAssociatedToUser = true,
|
||||
Id = card.Id
|
||||
});
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the calendar week of the year according to the ISO8601 standard (starts monday).
|
||||
/// </summary>
|
||||
|
||||
@ -76,10 +76,10 @@
|
||||
<tr>
|
||||
<td class="valign text-center">
|
||||
<!-- ko if: State -->
|
||||
<span class="label label-success" style="display: block">IN</span>
|
||||
<span class="label label-success" data-toggle="tooltip" data-placement="top" title="" data-bind="attr:{'title': $root.convertToDisplayDateTime(LastEventDateTime)}" style="display: block">IN</span>
|
||||
<!-- /ko -->
|
||||
<!-- ko if: !State -->
|
||||
<span class="label label-danger" style="display: block">OUT</span>
|
||||
<span class="label label-danger" data-toggle="tooltip" data-placement="top" title="" data-bind="attr:{'title': $root.convertToDisplayDateTime(LastEventDateTime)}" style="display: block">OUT</span>
|
||||
<!-- /ko -->
|
||||
</td>
|
||||
<td class="valign" data-bind="text: FirstName"></td>
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -76,7 +76,9 @@
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="App.config" />
|
||||
<None Include="App.config">
|
||||
<SubType>Designer</SubType>
|
||||
</None>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user