Skip to content

Commit

Permalink
Fix last modified timezone and make value dynamic
Browse files Browse the repository at this point in the history
  • Loading branch information
ml-evs committed Aug 23, 2023
1 parent e349afd commit 4bb3c9a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 17 deletions.
2 changes: 1 addition & 1 deletion pydatalab/pydatalab/routes/v0_1/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def create_collection():
409, # 409: Conflict
)

data["date"] = data.get("date", datetime.datetime.now())
data["last_modified"] = data.get("last_modified", datetime.datetime.now().isoformat())

try:
data_model = Collection(**data)
Expand Down
23 changes: 16 additions & 7 deletions webapp/src/views/CollectionPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
<span v-if="data_loaded && !savedStatus" class="navbar-text unsaved-warning">
Unsaved changes
</span>
<span v-if="data_loaded" class="navbar-text small mx-2"
><i>Last saved {{ lastModified }}</i></span
<span v-if="data_loaded && lastModified" class="navbar-text small mx-2"
><i>Last saved: {{ lastModified }}</i></span
>
<font-awesome-icon
icon="save"
Expand Down Expand Up @@ -52,6 +52,7 @@ export default {
data_loaded: false,
isMenuDropdownVisible: false,
isLoadingNewBlock: false,
lastModified: null,
};
},
methods: {
Expand All @@ -60,16 +61,28 @@ export default {
console.log("save clicked!");
tinymce.editors.forEach((editor) => editor.save());
saveCollection(this.collection_id);
this.lastModified = "just now";
},
async getCollection() {
await getCollectionData(this.collection_id);
this.data_loaded = true;
this.setLastModified();
},
leavePageWarningListener(event) {
event.preventDefault;
return (event.returnValue =
"Unsaved changes present. Would you like to leave without saving?");
},
setLastModified() {
let item_date = this.collection_data.last_modified || this.collection_data.date;
if (item_date == null) {
this.lastModified = "Unknown";
} else {
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date + "Z");
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
}
},
},
computed: {
itemTypeEntry() {
Expand All @@ -84,14 +97,10 @@ export default {
savedStatus() {
return this.$store.state.saved_status_collections[this.collection_id];
},
lastModified() {
let item_date = this.collection_data.last_modified;
const save_date = new Date(item_date);
return formatDistanceToNow(save_date, new Date(), { addSuffix: true });
},
},
created() {
this.getCollection();
this.interval = setInterval(() => this.setLastModified(), 30000);
},
components: {
CollectionInformation,
Expand Down
24 changes: 15 additions & 9 deletions webapp/src/views/EditPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
<span v-if="itemDataLoaded && !savedStatus" class="navbar-text unsaved-warning">
Unsaved changes
</span>
<span v-if="itemDataLoaded" class="navbar-text small mx-2"
<span v-if="itemDataLoaded && lastModified" class="navbar-text small mx-2"
><i>Last saved: {{ lastModified }}</i></span
>
<font-awesome-icon
Expand Down Expand Up @@ -119,6 +119,7 @@ export default {
isLoadingRemoteTree: false,
isLoadingRemoteFiles: false,
isLoadingNewBlock: false,
lastModified: null,
};
},
methods: {
Expand Down Expand Up @@ -170,6 +171,7 @@ export default {
editor.isDirty() && editor.save();
});
saveItem(this.item_id);
this.lastModified = "just now";
},
getSampleData() {
getItemData(this.item_id).then(() => {
Expand All @@ -180,13 +182,24 @@ export default {
console.log(`calling update on block ${block_id}`);
updateBlockFromServer(this.item_id, block_id, this.item_data.blocks_obj[block_id]);
});
this.setLastModified();
});
},
leavePageWarningListener(event) {
event.preventDefault;
return (event.returnValue =
"Unsaved changes present. Would you like to leave without saving?");
},
setLastModified() {
let item_date = this.item_data.last_modified || this.item_data.date;
if (item_date == null) {
this.lastModified = "Unknown";
} else {
// API dates are in UTC but missing Z suffix
const save_date = new Date(item_date + "Z");
this.lastModified = formatDistanceToNow(save_date, { addSuffix: true });
}
},
},
computed: {
itemType() {
Expand Down Expand Up @@ -214,14 +227,6 @@ export default {
);
return allBlocksAreSaved && this.$store.state.saved_status_items[this.item_id];
},
lastModified() {
let item_date = this.item_data.last_modified || this.item_data.date;
if (item_date == null) {
return "Unknown";
}
const save_date = new Date(item_date);
return formatDistanceToNow(save_date, { addSuffix: true });
},
files() {
return this.item_data.files;
},
Expand All @@ -234,6 +239,7 @@ export default {
},
created() {
this.getSampleData();
this.interval = setInterval(() => this.setLastModified(), 30000);
},
components: {
TinyMceInline,
Expand Down

0 comments on commit 4bb3c9a

Please sign in to comment.