Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix last modified timezone and make value dynamic #439

Merged
merged 2 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions webapp/cypress/e2e/batchSampleFeature.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,17 @@ describe("Batch sample creation", () => {
// as contains matches greedily, if any IDs have matching substrings they must be added in the appropriate order
it("deletes the rest of the samples (cleanup)", () => {
[
"test101_unique",
"test102_unique",
"test103_unique",
"test101_unique2",
"test101_unique",
"component1",
"component2",
"component3",
"component4",
"baseA_copy",
"baseB_copy",
"baseB_copy2",
"baseB_copy",
"test101",
"test102",
"test103",
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
Loading