diff --git a/app/server/static/js/document_classification.js b/app/server/static/js/document_classification.js index 6a599f13..05b0c2c1 100644 --- a/app/server/static/js/document_classification.js +++ b/app/server/static/js/document_classification.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import annotationMixin from './mixin'; import HTTP from './http'; -import simpleShortcut from './filter'; +import { simpleShortcut } from './filter'; Vue.use(require('vue-shortkey'), { prevent: ['input', 'textarea'], diff --git a/app/server/static/js/filter.js b/app/server/static/js/filter.js index d250ac6e..b0ac45bf 100644 --- a/app/server/static/js/filter.js +++ b/app/server/static/js/filter.js @@ -1,7 +1,27 @@ -export default function simpleShortcut(shortcut) { +export function simpleShortcut(shortcut) { let simplified = shortcut === null ? '' : shortcut; simplified = simplified.replace('ctrl', 'C'); simplified = simplified.replace('shift', 'S'); simplified = simplified.split(' ').join('-'); return simplified; } + +export function title(value) { + const string = (value || '').toString(); + return string.charAt(0).toUpperCase() + string.slice(1); +} + +export function daysAgo(dateStr) { + const updatedAt = new Date(dateStr); + const currentTm = new Date(); + + // difference between days(ms) + const msDiff = currentTm.getTime() - updatedAt.getTime(); + + // convert daysDiff(ms) to daysDiff(day) + const daysDiff = Math.floor(msDiff / (1000 * 60 * 60 * 24)); + + return daysDiff === 1 + ? `${daysDiff} day ago` + : `${daysDiff} days ago`; +} diff --git a/app/server/static/js/label.js b/app/server/static/js/label.js index 2571940f..1b92663f 100644 --- a/app/server/static/js/label.js +++ b/app/server/static/js/label.js @@ -1,6 +1,6 @@ import Vue from 'vue'; import HTTP from './http'; -import simpleShortcut from './filter'; +import { simpleShortcut } from './filter'; Vue.filter('simpleShortcut', simpleShortcut); diff --git a/app/server/static/js/projects.vue b/app/server/static/js/projects.vue index fa1de9b1..311b6a32 100644 --- a/app/server/static/js/projects.vue +++ b/app/server/static/js/projects.vue @@ -195,33 +195,14 @@