You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

79 lines
1.9 KiB

  1. import Vue from 'vue';
  2. import axios from 'axios';
  3. axios.defaults.xsrfCookieName = 'csrftoken';
  4. axios.defaults.xsrfHeaderName = 'X-CSRFToken';
  5. const baseUrl = window.location.href.split('/').slice(0, 3).join('/');
  6. const vm = new Vue({
  7. el: '#projects_root',
  8. delimiters: ['[[', ']]'],
  9. data: {
  10. items: [],
  11. isActive: false,
  12. isDelete: false,
  13. project: null,
  14. selected: 'All Project',
  15. },
  16. methods: {
  17. deleteProject() {
  18. axios.delete(`${baseUrl}/api/projects/${this.project.id}/`).then((response) => {
  19. this.isDelete = false;
  20. const index = this.items.indexOf(this.project);
  21. this.items.splice(index, 1);
  22. });
  23. },
  24. setProject(project) {
  25. this.project = project;
  26. this.isDelete = true;
  27. },
  28. matchType(projectType) {
  29. if (projectType === 'DocumentClassification') {
  30. return this.selected === 'Text Classification';
  31. }
  32. if (projectType === 'SequenceLabeling') {
  33. return this.selected === 'Sequence Labeling';
  34. }
  35. if (projectType === 'Seq2seq') {
  36. return this.selected === 'Seq2seq';
  37. }
  38. return false;
  39. },
  40. getDaysAgo(dateStr) {
  41. const updatedAt = new Date(dateStr);
  42. const currentTm = new Date();
  43. // difference between days(ms)
  44. const msDiff = currentTm.getTime() - updatedAt.getTime();
  45. // convert daysDiff(ms) to daysDiff(day)
  46. const daysDiff = Math.floor(msDiff / (1000 * 60 * 60 * 24));
  47. return daysDiff;
  48. },
  49. },
  50. computed: {
  51. selectedProjects() {
  52. const projects = [];
  53. for (let item of this.items) {
  54. if ((this.selected === 'All Project') || this.matchType(item.project_type)) {
  55. projects.push(item);
  56. }
  57. }
  58. return projects;
  59. },
  60. },
  61. created() {
  62. axios.get(`${baseUrl}/api/projects`).then((response) => {
  63. this.items = response.data;
  64. });
  65. },
  66. });