From 19b718a9464f3d0013307432632ac9ae74848ea1 Mon Sep 17 00:00:00 2001 From: "Chris.Watts90@outlook.com" Date: Fri, 10 Feb 2017 12:07:02 +0000 Subject: [PATCH] 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 --- .../Interfaces/IRepository.cs | 10 ++-- .../Interfaces/TimeLogList.cs | 5 +- .../SQLiteRepository/SQLiteRepository.cs | 8 +-- .../Controllers/TimelogController.cs | 6 +- .../WindowsDataCenter/www/spa.js | 55 ++++++++++--------- 5 files changed, 45 insertions(+), 39 deletions(-) diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs index 24b0e4c..6a53b7f 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/IRepository.cs @@ -1,4 +1,6 @@ -namespace Interfaces +using System; + +namespace Interfaces { public interface IRepository { @@ -48,14 +50,14 @@ /// /// integer data type, the Id of the user to get time logs for /// - /// - /// 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). /// /// /// with nested objects /// for the current calendar week /// - TimeLogList GetTimeLogs(int userId, int calendarWeek); + TimeLogList GetTimeLogs(int userId, DateTime selectedDate); /// /// Get a full list of Identifiers which are not associated to a user. /// diff --git a/DataCenter_Windows/WindowsDataCenter/Interfaces/TimeLogList.cs b/DataCenter_Windows/WindowsDataCenter/Interfaces/TimeLogList.cs index 3fb8a0c..0d44949 100644 --- a/DataCenter_Windows/WindowsDataCenter/Interfaces/TimeLogList.cs +++ b/DataCenter_Windows/WindowsDataCenter/Interfaces/TimeLogList.cs @@ -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(); } + public DateTime SelectedDate { get; set; } public int CalendarWeek { get; set; } public int TimeLogCount { get { return TimeLogs.Count; } } public List TimeLogs { get; set; } } - //TODO: group by day of week. } \ No newline at end of file diff --git a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs index d8c4157..b068a86 100644 --- a/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs +++ b/DataCenter_Windows/WindowsDataCenter/SQLiteRepository/SQLiteRepository.cs @@ -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; } diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/TimelogController.cs b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/TimelogController.cs index 750c3e5..f6a01e6 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/TimelogController.cs +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/Controllers/TimelogController.cs @@ -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) diff --git a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js index 734b99b..3e3930a 100644 --- a/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js +++ b/DataCenter_Windows/WindowsDataCenter/WindowsDataCenter/www/spa.js @@ -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());