Browse Source

Move custom filters to their own module

pull/148/head
Clemens Wolff 5 years ago
parent
commit
9d7b404e7b
5 changed files with 26 additions and 25 deletions
  1. 2
      app/server/static/js/document_classification.js
  2. 22
      app/server/static/js/filter.js
  3. 2
      app/server/static/js/label.js
  4. 23
      app/server/static/js/projects.vue
  5. 2
      app/server/static/js/sequence_labeling.js

2
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'],

22
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`;
}

2
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);

23
app/server/static/js/projects.vue

@ -195,33 +195,14 @@
<script>
import axios from 'axios';
import { title, daysAgo } from './filter';
axios.defaults.xsrfCookieName = 'csrftoken';
axios.defaults.xsrfHeaderName = 'X-CSRFToken';
const baseUrl = window.location.href.split('/').slice(0, 3).join('/');
export default {
filters: {
title: (value) => {
const string = (value || '').toString();
return string.charAt(0).toUpperCase() + string.slice(1);
},
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`;
},
},
filters: { title, daysAgo },
props: {
username: {

2
app/server/static/js/sequence_labeling.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'],

Loading…
Cancel
Save