File tree Expand file tree Collapse file tree 4 files changed +42
-18
lines changed Expand file tree Collapse file tree 4 files changed +42
-18
lines changed Original file line number Diff line number Diff line change 11from flask_restplus import Namespace , Resource , reqparse
22from flask_login import login_required , current_user
3+ from mongoengine .errors import NotUniqueError
34
45from ..util .pagination_util import Pagination
56from ..util import query_util
@@ -37,7 +38,7 @@ def post(self):
3738 supercategory = args .get ('supercategory' )
3839 metadata = args .get ('metadata' , {})
3940 color = args .get ('color' )
40-
41+
4142 try :
4243 category = CategoryModel (
4344 name = name ,
@@ -46,8 +47,8 @@ def post(self):
4647 metadata = metadata
4748 )
4849 category .save ()
49- except ( ValueError , TypeError ) as e :
50- return {'message' : str ( e ) }, 400
50+ except NotUniqueError as e :
51+ return {'message' : 'Category already exists. Check the undo tab to fully delete the category.' }, 400
5152
5253 return query_util .fix_ids (category )
5354
Original file line number Diff line number Diff line change 1+ import axios from "axios" ;
2+
3+ const baseURL = "/api/category/" ;
4+
5+ export default {
6+ allData ( params ) {
7+ return axios . get ( baseURL + "data" , {
8+ params : {
9+ ...params
10+ }
11+ } ) ;
12+ } ,
13+ create ( create ) {
14+ return axios . post ( baseURL , { ...create } ) ;
15+ }
16+ } ;
Original file line number Diff line number Diff line change 146146</template >
147147
148148<script >
149- import axios from " axios" ;
149+ import toastrs from " @/mixins/toastrs" ;
150+
151+ import Category from " @/models/categories" ;
150152import CategoryCard from " @/components/cards/CategoryCard" ;
151153import Pagination from " @/components/Pagination" ;
152154
@@ -155,6 +157,7 @@ import { mapMutations } from "vuex";
155157export default {
156158 name: " Categories" ,
157159 components: { CategoryCard, Pagination },
160+ mixins: [toastrs],
158161 data () {
159162 return {
160163 categoryCount: 0 ,
@@ -178,13 +181,10 @@ export default {
178181 page = page || this .page ;
179182 this .page = page;
180183
181- axios
182- .get (" /api/category/data" , {
183- params: {
184- page: page,
185- limit: this .limit
186- }
187- })
184+ Category .allData ({
185+ page: page,
186+ limit: this .limit
187+ })
188188 .then (response => {
189189 this .categories = response .data .categories ;
190190 this .page = response .data .pagination .page ;
@@ -196,13 +196,18 @@ export default {
196196 createCategory () {
197197 if (this .createName .length < 1 ) return ;
198198
199- axios
200- .post (" /api/category/" , {
201- name: this .createName
202- })
199+ Category .create ({
200+ name: this .createName
201+ })
203202 .then (() => {
204203 this .createName = " " ;
205204 this .updatePage ();
205+ })
206+ .catch (error => {
207+ this .axiosReqestError (
208+ " Creating Category" ,
209+ error .response .data .message
210+ );
206211 });
207212 },
208213 previousPage () {
Original file line number Diff line number Diff line change @@ -410,8 +410,8 @@ export default {
410410 queryAnnotated () {
411411 let showAnnotated = this .panel .showAnnotated ;
412412 let showNotAnnotated = this .panel .showNotAnnotated ;
413-
414- if (showAnnotated && showNotAnnotated) return null
413+
414+ if (showAnnotated && showNotAnnotated) return null ;
415415 if (! showAnnotated && ! showNotAnnotated) return " " ;
416416
417417 return showAnnotated;
@@ -446,7 +446,9 @@ export default {
446446 }
447447 },
448448 watch: {
449- queryAnnotated () { this .updatePage () },
449+ queryAnnotated () {
450+ this .updatePage ();
451+ },
450452 folders () {
451453 this .updatePage ();
452454 },
You can’t perform that action at this time.
0 commit comments