From 9d7b404e7b4dfd5558f8d2f6475a4f8a50e4220a Mon Sep 17 00:00:00 2001 From: Clemens Wolff Date: Wed, 10 Apr 2019 14:49:05 -0400 Subject: [PATCH] Move custom filters to their own module --- .../static/js/document_classification.js | 2 +- app/server/static/js/filter.js | 22 +++++++++++++++++- app/server/static/js/label.js | 2 +- app/server/static/js/projects.vue | 23 ++----------------- app/server/static/js/sequence_labeling.js | 2 +- 5 files changed, 26 insertions(+), 25 deletions(-) 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 @@