Skip to content

Commit f479768

Browse files
committed
Created category model, closes #76
1 parent e0a3f2f commit f479768

File tree

4 files changed

+42
-18
lines changed

4 files changed

+42
-18
lines changed

app/api/categories.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from flask_restplus import Namespace, Resource, reqparse
22
from flask_login import login_required, current_user
3+
from mongoengine.errors import NotUniqueError
34

45
from ..util.pagination_util import Pagination
56
from ..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

client/src/models/categories.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
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+
};

client/src/views/Categories.vue

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,9 @@
146146
</template>
147147

148148
<script>
149-
import axios from "axios";
149+
import toastrs from "@/mixins/toastrs";
150+
151+
import Category from "@/models/categories";
150152
import CategoryCard from "@/components/cards/CategoryCard";
151153
import Pagination from "@/components/Pagination";
152154
@@ -155,6 +157,7 @@ import { mapMutations } from "vuex";
155157
export 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() {

client/src/views/Dataset.vue

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff 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
},

0 commit comments

Comments
 (0)