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.

69 lines
2.1 KiB

6 years ago
  1. axios.defaults.xsrfCookieName = 'csrftoken';
  2. axios.defaults.xsrfHeaderName = 'X-CSRFToken';
  3. var base_url = window.location.href.split('/').slice(3, 5).join('/');
  4. const HTTP = axios.create({
  5. baseURL: `/api/${base_url}/`,
  6. })
  7. var vm = new Vue({
  8. el: '#root',
  9. delimiters: ['[[', ']]'],
  10. data: {
  11. labels: [],
  12. file: null,
  13. file_name: '',
  14. newLabel: '',
  15. newShortcut: '',
  16. total: 0,
  17. remaining: 0,
  18. backgroundColor: '#209cee',
  19. },
  20. methods: {
  21. handleFileUpload() {
  22. this.file = this.$refs.file.files[0];
  23. this.file_name = this.file.name;
  24. },
  25. submitFile() {
  26. let formData = new FormData();
  27. formData.append('file', this.file);
  28. axios.post('/' + base_url + '/apis/raw_data',
  29. formData, {
  30. headers: {
  31. 'Content-Type': 'multipart/form-data'
  32. }
  33. }
  34. ).then(function () {
  35. console.log('SUCCESS!!');
  36. })
  37. .catch(function () {
  38. console.log('FAILURE!!');
  39. });
  40. },
  41. addLabel: function () {
  42. var payload = {
  43. text: this.newLabel,
  44. shortcut: this.newShortcut
  45. };
  46. HTTP.post('labels/', payload).then(response => {
  47. this.newLabel = '';
  48. this.newShortcut = '';
  49. this.labels.push(response.data);
  50. })
  51. },
  52. removeLabel: function (index) {
  53. var label_id = this.labels[index].id;
  54. HTTP.delete(`labels/${label_id}`).then(response => {
  55. this.labels.splice(index, 1)
  56. })
  57. }
  58. },
  59. created: function () {
  60. HTTP.get('labels').then(response => {
  61. this.labels = response.data
  62. })
  63. HTTP.get('progress').then(response => {
  64. this.total = response.data['total'];
  65. this.remaining = response.data['remaining'];
  66. })
  67. }
  68. })