changed IRepository to accept a DateTime for the arg, instead of an int for calendar week/year.
added SelectedDate to the TimeLog object. changed the timelog controller to accept a datetime as an arg, instead of the previous calendarweek/year args. This kills two birds with one arg. Changed the goToTimeLogs function to accept an args object to allow passing of datetime SelectedDate parameter. removed console.logs to tidy code a little. corrected some "undefined" parameter bugs/errors. #5
This commit is contained in:
parent
ced578e05d
commit
19b718a946
@ -1,4 +1,6 @@
|
|||||||
namespace Interfaces
|
using System;
|
||||||
|
|
||||||
|
namespace Interfaces
|
||||||
{
|
{
|
||||||
public interface IRepository
|
public interface IRepository
|
||||||
{
|
{
|
||||||
@ -48,14 +50,14 @@
|
|||||||
/// <param name="userId">
|
/// <param name="userId">
|
||||||
/// integer data type, the Id of the user to get time logs for
|
/// integer data type, the Id of the user to get time logs for
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <param name="calendarWeek">
|
/// <param name="selectedDate">
|
||||||
/// integer data type, the calendar week to retrieve logs for.
|
/// datetime data type, the date to receive time logs for (will scope out to calendar week).
|
||||||
/// </param>
|
/// </param>
|
||||||
/// <returns>
|
/// <returns>
|
||||||
/// <see cref="TimeLogList"/> with nested <see cref="TimeLog"/> objects
|
/// <see cref="TimeLogList"/> with nested <see cref="TimeLog"/> objects
|
||||||
/// for the current calendar week
|
/// for the current calendar week
|
||||||
/// </returns>
|
/// </returns>
|
||||||
TimeLogList GetTimeLogs(int userId, int calendarWeek);
|
TimeLogList GetTimeLogs(int userId, DateTime selectedDate);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get a full list of Identifiers which are not associated to a user.
|
/// Get a full list of Identifiers which are not associated to a user.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace Interfaces
|
namespace Interfaces
|
||||||
{
|
{
|
||||||
@ -8,9 +9,9 @@ namespace Interfaces
|
|||||||
{
|
{
|
||||||
TimeLogs = new List<TimeLog>();
|
TimeLogs = new List<TimeLog>();
|
||||||
}
|
}
|
||||||
|
public DateTime SelectedDate { get; set; }
|
||||||
public int CalendarWeek { get; set; }
|
public int CalendarWeek { get; set; }
|
||||||
public int TimeLogCount { get { return TimeLogs.Count; } }
|
public int TimeLogCount { get { return TimeLogs.Count; } }
|
||||||
public List<TimeLog> TimeLogs { get; set; }
|
public List<TimeLog> TimeLogs { get; set; }
|
||||||
}
|
}
|
||||||
//TODO: group by day of week.
|
|
||||||
}
|
}
|
||||||
@ -136,13 +136,13 @@ namespace SQLiteRepository
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TimeLogList GetTimeLogs(int userId, int calendarWeek)
|
public TimeLogList GetTimeLogs(int userId, DateTime selectedDate)
|
||||||
{
|
{
|
||||||
var ret = new TimeLogList();
|
var ret = new TimeLogList {SelectedDate = selectedDate};
|
||||||
var now = DateTime.UtcNow;
|
var calendarWeek = GetIso8601CalendarWeek(selectedDate);
|
||||||
ret.CalendarWeek = calendarWeek;
|
ret.CalendarWeek = calendarWeek;
|
||||||
|
|
||||||
ret.TimeLogs = GetTimeLogList(userId, calendarWeek, now.Year);
|
ret.TimeLogs = GetTimeLogList(userId, calendarWeek, selectedDate.Year);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -24,16 +24,16 @@ namespace WindowsDataCenter
|
|||||||
|
|
||||||
[Route("")]
|
[Route("")]
|
||||||
[CacheControl(MaxAge = 0)]
|
[CacheControl(MaxAge = 0)]
|
||||||
public IHttpActionResult GetTimeLogs([FromUri]int userId, [FromUri] int calendarWeek = -1, [FromUri] int year = -1)
|
public IHttpActionResult GetTimeLogs([FromUri]int userId, [FromUri] DateTime? selectedDate = null)
|
||||||
{
|
{
|
||||||
TimeLogList logList;
|
TimeLogList logList;
|
||||||
if (calendarWeek == -1)
|
if (selectedDate == null)
|
||||||
{
|
{
|
||||||
logList = _repo.GetTimeLogs(userId);
|
logList = _repo.GetTimeLogs(userId);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
logList = _repo.GetTimeLogs(userId, calendarWeek);
|
logList = _repo.GetTimeLogs(userId, selectedDate.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
var msg = new HttpResponseMessage(HttpStatusCode.OK)
|
var msg = new HttpResponseMessage(HttpStatusCode.OK)
|
||||||
|
|||||||
@ -26,10 +26,20 @@
|
|||||||
};
|
};
|
||||||
self.goToMenuOption = function (menu) { location.hash = menu; console.log("goToMenuOption: " + menu); };
|
self.goToMenuOption = function (menu) { location.hash = menu; console.log("goToMenuOption: " + menu); };
|
||||||
self.goToUserDetails = function (user) { location.hash = self.uiPages.userDetails + "/" + user.UserId; };
|
self.goToUserDetails = function (user) { location.hash = self.uiPages.userDetails + "/" + user.UserId; };
|
||||||
self.goToTimeLogs = function (user, week) {
|
self.goToTimeLogs = function (user, data, args) {
|
||||||
var url = "timelogs" + "/" + user.UserId;
|
var userId;
|
||||||
if (week) {
|
if (user.UserId) {
|
||||||
url += "/" + week;
|
userId = user.UserId;
|
||||||
|
} else {
|
||||||
|
userId = user;
|
||||||
|
}
|
||||||
|
var url = "timelogs" + "/" + userId;
|
||||||
|
if (args) {
|
||||||
|
var appender = "?";
|
||||||
|
args.forEach(function(arg) {
|
||||||
|
url += appender + arg.key + "=" + arg.value;
|
||||||
|
appender = "&";
|
||||||
|
});
|
||||||
}
|
}
|
||||||
location.hash = url;
|
location.hash = url;
|
||||||
};
|
};
|
||||||
@ -67,8 +77,7 @@
|
|||||||
};
|
};
|
||||||
self.selectedCalendarWeek.subscribe(function (selectedWeek) {
|
self.selectedCalendarWeek.subscribe(function (selectedWeek) {
|
||||||
console.log("Calendar week changed to: " + selectedWeek);
|
console.log("Calendar week changed to: " + selectedWeek);
|
||||||
self.goToTimeLogs(self.chosenTimeLogUserId, selectedWeek);
|
//self.goToTimeLogs(self.chosenTimeLogUserId, selectedWeek);
|
||||||
//self.getTimeLogData(self.chosenTimeLogUserId, selectedWeek);
|
|
||||||
});
|
});
|
||||||
/**
|
/**
|
||||||
* Create a request URL - references apiEndpoints object to construct url with args, and optional callback url.
|
* Create a request URL - references apiEndpoints object to construct url with args, and optional callback url.
|
||||||
@ -146,21 +155,17 @@
|
|||||||
console.log("finished init");
|
console.log("finished init");
|
||||||
};
|
};
|
||||||
self.assignHandler = function () {
|
self.assignHandler = function () {
|
||||||
//console.log('shall I assign?');
|
|
||||||
var elem = $("#weeklyDatePicker")[0];
|
var elem = $("#weeklyDatePicker")[0];
|
||||||
var data = jQuery.hasData(elem) && jQuery._data(elem);
|
var data = jQuery.hasData(elem) && jQuery._data(elem);
|
||||||
if (!data.events.changeDate) {
|
if (!data.events.changeDate) {
|
||||||
//console.log("assigning..");
|
|
||||||
$("#weeklyDatePicker").on("changeDate", function (e) {
|
$("#weeklyDatePicker").on("changeDate", function (e) {
|
||||||
var kk = e.date;
|
var kk = e.date;
|
||||||
//console.log(kk);
|
|
||||||
//console.log(
|
//console.log(
|
||||||
// "1: Iso Week Number: " + moment(kk).isoWeek() + " of " +
|
// "1: Iso Week Number: " + moment(kk).isoWeek() + " of " +
|
||||||
// moment(kk).weeksInYear()
|
// moment(kk).weeksInYear()
|
||||||
//);
|
//);
|
||||||
//console.log("before: " + self.selectedCalendarWeek());
|
|
||||||
self.selectedCalendarWeek(moment(kk).isoWeek());
|
self.selectedCalendarWeek(moment(kk).isoWeek());
|
||||||
//console.log("after: " + self.selectedCalendarWeek());
|
self.goToTimeLogs(self.chosenTimeLogUserId, null, [{ key: "selectedDate", value: kk.toISOString() }]);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -214,9 +219,13 @@
|
|||||||
self.goToMenuOption(self.uiPages.home());
|
self.goToMenuOption(self.uiPages.home());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
self.getTimeLogData = function (userId, calendarWeek) {
|
self.getTimeLogData = function (userId, selectedDate) {
|
||||||
|
var urlArgs = [{ key: "userId", value: userId }];
|
||||||
|
if (selectedDate) {
|
||||||
|
urlArgs.push({ key: "selectedDate", value: selectedDate });
|
||||||
|
}
|
||||||
var url = self.createRequestUrl(self.apiEndpoints.getTimeLogs,
|
var url = self.createRequestUrl(self.apiEndpoints.getTimeLogs,
|
||||||
[{ key: "userId", value: userId }, { key: "calendarWeek", value: calendarWeek }],
|
urlArgs,
|
||||||
false);
|
false);
|
||||||
$.getJSON(url, function (res) {
|
$.getJSON(url, function (res) {
|
||||||
self.userTimeLogData(res);
|
self.userTimeLogData(res);
|
||||||
@ -261,18 +270,16 @@
|
|||||||
self.getUnassignedCardData();
|
self.getUnassignedCardData();
|
||||||
//$.get("http://localhost:3000", { menu: this.params.menu }, self.chosenMenuData);
|
//$.get("http://localhost:3000", { menu: this.params.menu }, self.chosenMenuData);
|
||||||
});
|
});
|
||||||
this.get("#timelogs/:userId/:calendarWeek", function () {
|
this.get("#timelogs/:userId", function () {
|
||||||
|
var selectedDate = this.params.selectedDate;
|
||||||
self.chosenMenuItemId("Other");
|
self.chosenMenuItemId("Other");
|
||||||
self.userList(null);
|
self.userList(null);
|
||||||
self.chosenUserDetails(null);
|
self.chosenUserDetails(null);
|
||||||
self.chosenTimeLogUserId = this.params.userId;
|
self.chosenTimeLogUserId = this.params.userId;
|
||||||
var week;
|
//if (!selectedDate) {
|
||||||
if (self.params.calendarWeek) {
|
// selectedDate = new Date();
|
||||||
week = this.params.calendarWeek;
|
//}
|
||||||
} else {
|
self.getTimeLogData(this.params.userId, selectedDate);
|
||||||
week = self.selectedCalendarWeek();
|
|
||||||
}
|
|
||||||
self.getTimeLogData(this.params.userId, week);
|
|
||||||
});
|
});
|
||||||
this.get("#newUser", function () {
|
this.get("#newUser", function () {
|
||||||
self.chosenMenuItemId("newUser");
|
self.chosenMenuItemId("newUser");
|
||||||
@ -295,23 +302,19 @@
|
|||||||
$.each(self.chosenUserDetails().AssociatedIdentifiers,
|
$.each(self.chosenUserDetails().AssociatedIdentifiers,
|
||||||
function (k, v) {
|
function (k, v) {
|
||||||
if (v.IsAssociatedToUser !== true) {
|
if (v.IsAssociatedToUser !== true) {
|
||||||
console.log("removing..");
|
|
||||||
self.chosenUserDetails().AssociatedIdentifiers.splice(k, 1);
|
self.chosenUserDetails().AssociatedIdentifiers.splice(k, 1);
|
||||||
console.log(v.UniqueId);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$.each(self.unassignedCardData().data, function (k, v) {
|
$.each(self.unassignedCardData().data, function (k, v) {
|
||||||
if (v.IsAssociatedToUser === true) {
|
if (v.IsAssociatedToUser === true) {
|
||||||
self.chosenUserDetails().AssociatedIdentifiers.push(v);
|
self.chosenUserDetails().AssociatedIdentifiers.push(v);
|
||||||
console.log(v.UniqueId);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//console.log(self.chosenUserDetails());
|
|
||||||
self.submitChangedUser(self.chosenUserDetails());
|
self.submitChangedUser(self.chosenUserDetails());
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
//default route (home page)
|
//default route (home page)
|
||||||
this.get("", function () { this.app.runRoute("get", "#" + self.uiPages.users) });
|
this.get("", function () { this.app.runRoute("get", "#" + self.uiPages.home()) });
|
||||||
}).run();
|
}).run();
|
||||||
};
|
};
|
||||||
ko.applyBindings(new DataVM());
|
ko.applyBindings(new DataVM());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user