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
|
||||
{
|
||||
@ -48,14 +50,14 @@
|
||||
/// <param name="userId">
|
||||
/// integer data type, the Id of the user to get time logs for
|
||||
/// </param>
|
||||
/// <param name="calendarWeek">
|
||||
/// integer data type, the calendar week to retrieve logs for.
|
||||
/// <param name="selectedDate">
|
||||
/// datetime data type, the date to receive time logs for (will scope out to calendar week).
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// <see cref="TimeLogList"/> with nested <see cref="TimeLog"/> objects
|
||||
/// for the current calendar week
|
||||
/// </returns>
|
||||
TimeLogList GetTimeLogs(int userId, int calendarWeek);
|
||||
TimeLogList GetTimeLogs(int userId, DateTime selectedDate);
|
||||
/// <summary>
|
||||
/// Get a full list of Identifiers which are not associated to a user.
|
||||
/// </summary>
|
||||
|
||||
@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Interfaces
|
||||
{
|
||||
@ -8,9 +9,9 @@ namespace Interfaces
|
||||
{
|
||||
TimeLogs = new List<TimeLog>();
|
||||
}
|
||||
public DateTime SelectedDate { get; set; }
|
||||
public int CalendarWeek { get; set; }
|
||||
public int TimeLogCount { get { return TimeLogs.Count; } }
|
||||
public List<TimeLog> TimeLogs { get; set; }
|
||||
}
|
||||
//TODO: group by day of week.
|
||||
}
|
||||
@ -136,13 +136,13 @@ namespace SQLiteRepository
|
||||
return ret;
|
||||
}
|
||||
|
||||
public TimeLogList GetTimeLogs(int userId, int calendarWeek)
|
||||
public TimeLogList GetTimeLogs(int userId, DateTime selectedDate)
|
||||
{
|
||||
var ret = new TimeLogList();
|
||||
var now = DateTime.UtcNow;
|
||||
var ret = new TimeLogList {SelectedDate = selectedDate};
|
||||
var calendarWeek = GetIso8601CalendarWeek(selectedDate);
|
||||
ret.CalendarWeek = calendarWeek;
|
||||
|
||||
ret.TimeLogs = GetTimeLogList(userId, calendarWeek, now.Year);
|
||||
ret.TimeLogs = GetTimeLogList(userId, calendarWeek, selectedDate.Year);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -24,16 +24,16 @@ namespace WindowsDataCenter
|
||||
|
||||
[Route("")]
|
||||
[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;
|
||||
if (calendarWeek == -1)
|
||||
if (selectedDate == null)
|
||||
{
|
||||
logList = _repo.GetTimeLogs(userId);
|
||||
}
|
||||
else
|
||||
{
|
||||
logList = _repo.GetTimeLogs(userId, calendarWeek);
|
||||
logList = _repo.GetTimeLogs(userId, selectedDate.Value);
|
||||
}
|
||||
|
||||
var msg = new HttpResponseMessage(HttpStatusCode.OK)
|
||||
|
||||
@ -26,10 +26,20 @@
|
||||
};
|
||||
self.goToMenuOption = function (menu) { location.hash = menu; console.log("goToMenuOption: " + menu); };
|
||||
self.goToUserDetails = function (user) { location.hash = self.uiPages.userDetails + "/" + user.UserId; };
|
||||
self.goToTimeLogs = function (user, week) {
|
||||
var url = "timelogs" + "/" + user.UserId;
|
||||
if (week) {
|
||||
url += "/" + week;
|
||||
self.goToTimeLogs = function (user, data, args) {
|
||||
var userId;
|
||||
if (user.UserId) {
|
||||
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;
|
||||
};
|
||||
@ -67,8 +77,7 @@
|
||||
};
|
||||
self.selectedCalendarWeek.subscribe(function (selectedWeek) {
|
||||
console.log("Calendar week changed to: " + selectedWeek);
|
||||
self.goToTimeLogs(self.chosenTimeLogUserId, selectedWeek);
|
||||
//self.getTimeLogData(self.chosenTimeLogUserId, selectedWeek);
|
||||
//self.goToTimeLogs(self.chosenTimeLogUserId, selectedWeek);
|
||||
});
|
||||
/**
|
||||
* Create a request URL - references apiEndpoints object to construct url with args, and optional callback url.
|
||||
@ -146,21 +155,17 @@
|
||||
console.log("finished init");
|
||||
};
|
||||
self.assignHandler = function () {
|
||||
//console.log('shall I assign?');
|
||||
var elem = $("#weeklyDatePicker")[0];
|
||||
var data = jQuery.hasData(elem) && jQuery._data(elem);
|
||||
if (!data.events.changeDate) {
|
||||
//console.log("assigning..");
|
||||
$("#weeklyDatePicker").on("changeDate", function (e) {
|
||||
var kk = e.date;
|
||||
//console.log(kk);
|
||||
//console.log(
|
||||
// "1: Iso Week Number: " + moment(kk).isoWeek() + " of " +
|
||||
// moment(kk).weeksInYear()
|
||||
//);
|
||||
//console.log("before: " + self.selectedCalendarWeek());
|
||||
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.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,
|
||||
[{ key: "userId", value: userId }, { key: "calendarWeek", value: calendarWeek }],
|
||||
urlArgs,
|
||||
false);
|
||||
$.getJSON(url, function (res) {
|
||||
self.userTimeLogData(res);
|
||||
@ -261,18 +270,16 @@
|
||||
self.getUnassignedCardData();
|
||||
//$.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.userList(null);
|
||||
self.chosenUserDetails(null);
|
||||
self.chosenTimeLogUserId = this.params.userId;
|
||||
var week;
|
||||
if (self.params.calendarWeek) {
|
||||
week = this.params.calendarWeek;
|
||||
} else {
|
||||
week = self.selectedCalendarWeek();
|
||||
}
|
||||
self.getTimeLogData(this.params.userId, week);
|
||||
//if (!selectedDate) {
|
||||
// selectedDate = new Date();
|
||||
//}
|
||||
self.getTimeLogData(this.params.userId, selectedDate);
|
||||
});
|
||||
this.get("#newUser", function () {
|
||||
self.chosenMenuItemId("newUser");
|
||||
@ -295,23 +302,19 @@
|
||||
$.each(self.chosenUserDetails().AssociatedIdentifiers,
|
||||
function (k, v) {
|
||||
if (v.IsAssociatedToUser !== true) {
|
||||
console.log("removing..");
|
||||
self.chosenUserDetails().AssociatedIdentifiers.splice(k, 1);
|
||||
console.log(v.UniqueId);
|
||||
}
|
||||
});
|
||||
$.each(self.unassignedCardData().data, function (k, v) {
|
||||
if (v.IsAssociatedToUser === true) {
|
||||
self.chosenUserDetails().AssociatedIdentifiers.push(v);
|
||||
console.log(v.UniqueId);
|
||||
}
|
||||
});
|
||||
//console.log(self.chosenUserDetails());
|
||||
self.submitChangedUser(self.chosenUserDetails());
|
||||
return false;
|
||||
});
|
||||
//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();
|
||||
};
|
||||
ko.applyBindings(new DataVM());
|
||||
|
||||
Loading…
Reference in New Issue
Block a user