From 4ab558df4489acb9f67919e759c971d40359a756 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Thu, 15 Nov 2018 22:06:47 +0900 Subject: [PATCH] Fix project deletion bug Always delete the latest project --- app/db.sqlite3 | Bin 35418112 -> 35418112 bytes app/server/static/bundle/projects.js | 2 +- app/server/static/js/projects.js | 12 +++++++++--- app/server/templates/projects.html | 4 ++-- 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/db.sqlite3 b/app/db.sqlite3 index c2891e106399deffa20a370f373391e86cdfae95..229a5de13db3c56ab925d030d97cfb092389bbf3 100644 GIT binary patch delta 3805 zcmb8v3s_U-1IO{5O<>673dMN7P;tb0_X{KdahGj{1v%7Y`TECzFr=I^)^z^WY?`M0?;XUs;@1A!Zz2{UN zXx&hud;PF!LEW;HAqRKOTaXeT6RlE=6&j@aW~qLTufEnJl{ZEWk5)_;{F>SFxZTm? z%X}qzEnbNkQu?ft!gzM&I#<3!^y_-#7VgW_ zRtocle!uyr%neyt8rdT&9UU8yo}QfdzbDbSYb&HisiE<2x1dYYSyCqGQ!P64znw9q z7D#nXQcby(<0_M?D{CqO+rs6Cr0?=x`_c2B~hNN**s@osN1t z`@KMY4hZC(O&BDEg$SW4nM{VasK9{)dBGGx?9z243G4bC)bE3T&7x9Ym?bL4f3Q|Q zgOlt`5;pbwdVLPyB!h*};0tpEV~S&ot zWw1&Xxj$lAxHU`}dPuoC#1ZV*X~vxD^Xh(F;Y{h0iOL}RvY_0z8gmP$R^{6ATb(wi+fiI(w0qo@j*RLmr_FA3+OkX~?L{W1 z*Xeb%XSF&DXL#*}RwM8eP$se>8=8)?P&T>(O||% zdb9!EfNn%Lp^eCoZbrADThVQ36S^JUfx6IUbSJtC-Ho=Ot>_-K4Q)sFqWjSO=mE3? zJ%}DcJJBxmFxrhCL64$6D1aVAkE18hlV~q`3O$YXp=Z#uXg}&k&!Okh3+Mnkh+ag8 z&`anrI)YwCub`voRrDG0~OIMlwhyu@W1ZPO?Zgxq{>nJ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$*Q=L~A)L-hNx}+|v z26bg_WQ|d+zyenA1|RSR8~A}gG=jzu0D)i!6M`TZLZAsWg-~b)&7lRfgfM6Y;m{h| zKwF4_8{kH02koH)+ypm+er`G^pd)mGTOkUfp))uj2Atr6Scrpo=mH6l2uW}o+zwsg z4(JBmAsKo=3iO0tkP2y#4!xld^o4%VA2MJ7WWqog1cM<9hQLr526w_;FdXiN5ik<& zfl)9TvSAG5z*xwIJQxS#As-5$5GFto6hjG=!o5%iTuovEieefRahXZgB4#8n~A3lI1@F9EzN8w{Q2A{xjH~}Z& z6r6@np&mYiGw?Zl0bjyb@HKn`-@^ObCKt2!STh6hfgHG=~<@62dHX KI{qxj4*v~Z8tO*? diff --git a/app/server/static/bundle/projects.js b/app/server/static/bundle/projects.js index 6d1498fe..bbbebf33 100644 --- a/app/server/static/bundle/projects.js +++ b/app/server/static/bundle/projects.js @@ -460,7 +460,7 @@ eval("var g;\n\n// This works in non-strict mode\ng = (function() {\n\treturn th /***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; -eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfCookieName = 'csrftoken';\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfHeaderName = 'X-CSRFToken';\nconst baseUrl = window.location.href.split('/').slice(0, 3).join('/');\n\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#projects_root',\n delimiters: ['[[', ']]'],\n data: {\n items: [],\n selectedType: 'All',\n isActive: false,\n isDelete: false,\n },\n\n methods: {\n getProjects() {\n axios__WEBPACK_IMPORTED_MODULE_1___default.a.get(`${baseUrl}/api/projects`).then((response) => {\n this.items = response.data;\n });\n },\n\n deleteProject(project) {\n axios__WEBPACK_IMPORTED_MODULE_1___default.a.delete(`${baseUrl}/api/projects/${project.id}/`).then((response) => {\n this.isDelete = false;\n const index = this.items.indexOf(project);\n this.items.splice(index, 1);\n });\n },\n\n updateSelectedType(type) {\n this.selectedType = type;\n },\n },\n\n computed: {\n uniqueProjectTypes() {\n const types = [];\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n types.push(item.project_type);\n }\n const uniqueTypes = Array.from(new Set(types));\n\n return uniqueTypes;\n },\n\n filteredProjects() {\n // filter projects\n const projects = [];\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n if ((this.selectedType === 'All') || (item.project_type === this.selectedType)) {\n projects.push(item);\n }\n }\n // create nested projects\n const nestedProjects = [];\n for (let i = 0; i < Math.ceil(projects.length / 3); i++) {\n const p = projects.slice(i * 3, (i + 1) * 3);\n nestedProjects.push(p);\n }\n return nestedProjects;\n },\n },\n\n created() {\n this.getProjects();\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/projects.js?"); +eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var vue__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! vue */ \"./node_modules/vue/dist/vue.esm.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(/*! axios */ \"./node_modules/axios/index.js\");\n/* harmony import */ var axios__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(axios__WEBPACK_IMPORTED_MODULE_1__);\n\n\n\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfCookieName = 'csrftoken';\naxios__WEBPACK_IMPORTED_MODULE_1___default.a.defaults.xsrfHeaderName = 'X-CSRFToken';\nconst baseUrl = window.location.href.split('/').slice(0, 3).join('/');\n\n\nconst vm = new vue__WEBPACK_IMPORTED_MODULE_0__[\"default\"]({\n el: '#projects_root',\n delimiters: ['[[', ']]'],\n data: {\n items: [],\n selectedType: 'All',\n isActive: false,\n isDelete: false,\n project: null,\n },\n\n methods: {\n getProjects() {\n axios__WEBPACK_IMPORTED_MODULE_1___default.a.get(`${baseUrl}/api/projects`).then((response) => {\n this.items = response.data;\n });\n },\n\n deleteProject() {\n axios__WEBPACK_IMPORTED_MODULE_1___default.a.delete(`${baseUrl}/api/projects/${this.project.id}/`).then((response) => {\n this.isDelete = false;\n const index = this.items.indexOf(this.project);\n this.items.splice(index, 1);\n });\n },\n\n setProject(project) {\n this.project = project;\n this.isDelete = true;\n },\n\n updateSelectedType(type) {\n this.selectedType = type;\n },\n },\n\n computed: {\n uniqueProjectTypes() {\n const types = [];\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n types.push(item.project_type);\n }\n const uniqueTypes = Array.from(new Set(types));\n\n return uniqueTypes;\n },\n\n filteredProjects() {\n // filter projects\n const projects = [];\n for (let i = 0; i < this.items.length; i++) {\n const item = this.items[i];\n if ((this.selectedType === 'All') || (item.project_type === this.selectedType)) {\n projects.push(item);\n }\n }\n // create nested projects\n const nestedProjects = [];\n for (let i = 0; i < Math.ceil(projects.length / 3); i++) {\n const p = projects.slice(i * 3, (i + 1) * 3);\n nestedProjects.push(p);\n }\n return nestedProjects;\n },\n },\n\n created() {\n this.getProjects();\n },\n});\n\n\n//# sourceURL=webpack:///./static/js/projects.js?"); /***/ }) diff --git a/app/server/static/js/projects.js b/app/server/static/js/projects.js index fd4829be..bf6b7991 100644 --- a/app/server/static/js/projects.js +++ b/app/server/static/js/projects.js @@ -14,6 +14,7 @@ const vm = new Vue({ selectedType: 'All', isActive: false, isDelete: false, + project: null, }, methods: { @@ -23,14 +24,19 @@ const vm = new Vue({ }); }, - deleteProject(project) { - axios.delete(`${baseUrl}/api/projects/${project.id}/`).then((response) => { + deleteProject() { + axios.delete(`${baseUrl}/api/projects/${this.project.id}/`).then((response) => { this.isDelete = false; - const index = this.items.indexOf(project); + const index = this.items.indexOf(this.project); this.items.splice(index, 1); }); }, + setProject(project) { + this.project = project; + this.isDelete = true; + }, + updateSelectedType(type) { this.selectedType = type; }, diff --git a/app/server/templates/projects.html b/app/server/templates/projects.html index 14c59104..417667c1 100644 --- a/app/server/templates/projects.html +++ b/app/server/templates/projects.html @@ -108,14 +108,14 @@ Are you sure you want to delete project?
- +
{% endif %}