Client updated at

This commit is contained in:
Mo Bitar
2018-06-01 11:03:57 -05:00
parent f17c5995c6
commit 53300ac1b6
5 changed files with 42 additions and 12 deletions

View File

@@ -326,19 +326,16 @@ angular.module('app')
this.togglePin = function() { this.togglePin = function() {
this.note.setAppDataItem("pinned", !this.note.pinned); this.note.setAppDataItem("pinned", !this.note.pinned);
this.note.setDirty(true);
this.changesMade(); this.changesMade();
} }
this.toggleLockNote = function() { this.toggleLockNote = function() {
this.note.setAppDataItem("locked", !this.note.locked); this.note.setAppDataItem("locked", !this.note.locked);
this.note.setDirty(true);
this.changesMade(); this.changesMade();
} }
this.toggleArchiveNote = function() { this.toggleArchiveNote = function() {
this.note.setAppDataItem("archived", !this.note.archived); this.note.setAppDataItem("archived", !this.note.archived);
this.note.setDirty(true);
this.changesMade(true); this.changesMade(true);
$rootScope.$broadcast("noteArchived"); $rootScope.$broadcast("noteArchived");
} }

View File

@@ -41,7 +41,14 @@ angular.module('app')
this.loadPreferences = function() { this.loadPreferences = function() {
let prevSortValue = this.sortBy; let prevSortValue = this.sortBy;
this.sortBy = authManager.getUserPrefValue("sortBy", "created_at"); this.sortBy = authManager.getUserPrefValue("sortBy", "created_at");
if(this.sortBy == "updated_at") {
// use client_updated_at instead
this.sortBy = "client_updated_at";
}
if(prevSortValue && prevSortValue != this.sortBy) { if(prevSortValue && prevSortValue != this.sortBy) {
$timeout(() => { $timeout(() => {
this.selectFirstNote(); this.selectFirstNote();
@@ -120,7 +127,7 @@ angular.module('app')
var base = ""; var base = "";
if(this.sortBy == "created_at") { if(this.sortBy == "created_at") {
base += " Date Added"; base += " Date Added";
} else if(this.sortBy == "updated_at") { } else if(this.sortBy == "client_updated_at") {
base += " Date Modifed"; base += " Date Modifed";
} else if(this.sortBy == "title") { } else if(this.sortBy == "title") {
base += " Title"; base += " Title";
@@ -274,7 +281,7 @@ angular.module('app')
} }
this.selectedSortByUpdated = function() { this.selectedSortByUpdated = function() {
this.setSortBy("updated_at"); this.setSortBy("client_updated_at");
this.sortDescending = true; this.sortDescending = true;
} }

View File

@@ -48,6 +48,9 @@ class Item {
this.updated_at = new Date(); this.updated_at = new Date();
} }
// Allows the getter to be re-invoked
this._client_updated_at = null;
if(json.content) { if(json.content) {
this.mapContentToLocalProperties(this.contentObject); this.mapContentToLocalProperties(this.contentObject);
} else if(json.deleted == true) { } else if(json.deleted == true) {
@@ -68,7 +71,7 @@ class Item {
// Subclasses can override // Subclasses can override
} }
setDirty(dirty) { setDirty(dirty, dontUpdateClientDate) {
this.dirty = dirty; this.dirty = dirty;
// Allows the syncManager to check if an item has been marked dirty after a sync has been started // Allows the syncManager to check if an item has been marked dirty after a sync has been started
@@ -81,6 +84,11 @@ class Item {
this.dirtyCount = 0; this.dirtyCount = 0;
} }
if(dirty && !dontUpdateClientDate) {
// Set the client modified date to now if marking the item as dirty
this.client_updated_at = new Date();
}
if(dirty) { if(dirty) {
this.notifyObserversOfChange(); this.notifyObserversOfChange();
} }
@@ -214,6 +222,24 @@ class Item {
return this.getAppDataItem("locked"); return this.getAppDataItem("locked");
} }
get client_updated_at() {
if(!this._client_updated_at) {
var saved = this.getAppDataItem("client_updated_at");
if(saved) {
this._client_updated_at = new Date(saved);
} else {
this._client_updated_at = new Date(this.updated_at);
}
}
return this._client_updated_at;
}
set client_updated_at(date) {
this._client_updated_at = date;
this.setAppDataItem("client_updated_at", date);
}
/* /*
During sync conflicts, when determing whether to create a duplicate for an item, we can omit keys that have no During sync conflicts, when determing whether to create a duplicate for an item, we can omit keys that have no
meaningful weight and can be ignored. For example, if one component has active = true and another component has active = false, meaningful weight and can be ignored. For example, if one component has active = true and another component has active = false,
@@ -245,7 +271,7 @@ class Item {
} }
updatedAtString() { updatedAtString() {
return this.dateToLocalizedString(this.updated_at); return this.dateToLocalizedString(this.client_updated_at);
} }
dateToLocalizedString(date) { dateToLocalizedString(date) {

View File

@@ -410,13 +410,13 @@ class ModelManager {
} }
/* Used when changing encryption key */ /* Used when changing encryption key */
setAllItemsDirty() { setAllItemsDirty(dontUpdateClientDates = true) {
var relevantItems = this.allItems.filter(function(item){ var relevantItems = this.allItems.filter(function(item){
return _.includes(this.acceptableContentTypes, item.content_type); return _.includes(this.acceptableContentTypes, item.content_type);
}.bind(this)); }.bind(this));
for(var item of relevantItems) { for(var item of relevantItems) {
item.setDirty(true); item.setDirty(true, dontUpdateClientDates);
} }
} }

View File

@@ -27,7 +27,7 @@
%h4.title Sort By %h4.title Sort By
%menu-row{"label" => "'Date Added'", "circle" => "ctrl.sortBy == 'created_at' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByCreated()", "desc" => "'Sort notes by newest first'"} %menu-row{"label" => "'Date Added'", "circle" => "ctrl.sortBy == 'created_at' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByCreated()", "desc" => "'Sort notes by newest first'"}
%menu-row{"label" => "'Date Modified'", "circle" => "ctrl.sortBy == 'updated_at' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByUpdated()", "desc" => "'Sort notes with the most recently updated first'"} %menu-row{"label" => "'Date Modified'", "circle" => "ctrl.sortBy == 'client_updated_at' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByUpdated()", "desc" => "'Sort notes with the most recently updated first'"}
%menu-row{"label" => "'Title'", "circle" => "ctrl.sortBy == 'title' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByTitle()", "desc" => "'Sort notes alphabetically by their title'"} %menu-row{"label" => "'Title'", "circle" => "ctrl.sortBy == 'title' && 'success'", "ng-click" => "ctrl.selectedMenuItem($event); ctrl.selectedSortByTitle()", "desc" => "'Sort notes alphabetically by their title'"}
.section{"ng-if" => "!ctrl.tag.archiveTag"} .section{"ng-if" => "!ctrl.tag.archiveTag"}
@@ -64,7 +64,7 @@
.note-preview{"ng-if" => "!ctrl.hideNotePreview"} .note-preview{"ng-if" => "!ctrl.hideNotePreview"}
{{note.text}} {{note.text}}
.date.faded{"ng-if" => "!ctrl.hideDate"} .date.faded{"ng-if" => "!ctrl.hideDate"}
%span{"ng-if" => "ctrl.sortBy == 'updated_at'"} Modified {{note.updatedAtString() || 'Now'}} %span{"ng-if" => "ctrl.sortBy == 'client_updated_at'"} Modified {{note.updatedAtString() || 'Now'}}
%span{"ng-if" => "ctrl.sortBy != 'updated_at'"} {{note.createdAtString() || 'Now'}} %span{"ng-if" => "ctrl.sortBy != 'client_updated_at'"} {{note.createdAtString() || 'Now'}}
%panel-resizer{"panel-id" => "'notes-column'", "on-resize-finish" => "ctrl.onPanelResize", "control" => "ctrl.panelController", "hoverable" => "true", "collapsable" => "true"} %panel-resizer{"panel-id" => "'notes-column'", "on-resize-finish" => "ctrl.onPanelResize", "control" => "ctrl.panelController", "hoverable" => "true", "collapsable" => "true"}