Skip to content

Commit

Permalink
Created category model, closes #76
Browse files Browse the repository at this point in the history
  • Loading branch information
jsbroks committed Feb 9, 2019
1 parent e0a3f2f commit f479768
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
7 changes: 4 additions & 3 deletions app/api/categories.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from flask_restplus import Namespace, Resource, reqparse
from flask_login import login_required, current_user
from mongoengine.errors import NotUniqueError

from ..util.pagination_util import Pagination
from ..util import query_util
Expand Down Expand Up @@ -37,7 +38,7 @@ def post(self):
supercategory = args.get('supercategory')
metadata = args.get('metadata', {})
color = args.get('color')

try:
category = CategoryModel(
name=name,
Expand All @@ -46,8 +47,8 @@ def post(self):
metadata=metadata
)
category.save()
except (ValueError, TypeError) as e:
return {'message': str(e)}, 400
except NotUniqueError as e:
return {'message': 'Category already exists. Check the undo tab to fully delete the category.'}, 400

return query_util.fix_ids(category)

Expand Down
16 changes: 16 additions & 0 deletions client/src/models/categories.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import axios from "axios";

const baseURL = "/api/category/";

export default {
allData(params) {
return axios.get(baseURL + "data", {
params: {
...params
}
});
},
create(create) {
return axios.post(baseURL, { ...create });
}
};
29 changes: 17 additions & 12 deletions client/src/views/Categories.vue
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,9 @@
</template>

<script>
import axios from "axios";
import toastrs from "@/mixins/toastrs";
import Category from "@/models/categories";
import CategoryCard from "@/components/cards/CategoryCard";
import Pagination from "@/components/Pagination";
Expand All @@ -155,6 +157,7 @@ import { mapMutations } from "vuex";
export default {
name: "Categories",
components: { CategoryCard, Pagination },
mixins: [toastrs],
data() {
return {
categoryCount: 0,
Expand All @@ -178,13 +181,10 @@ export default {
page = page || this.page;
this.page = page;
axios
.get("/api/category/data", {
params: {
page: page,
limit: this.limit
}
})
Category.allData({
page: page,
limit: this.limit
})
.then(response => {
this.categories = response.data.categories;
this.page = response.data.pagination.page;
Expand All @@ -196,13 +196,18 @@ export default {
createCategory() {
if (this.createName.length < 1) return;
axios
.post("/api/category/", {
name: this.createName
})
Category.create({
name: this.createName
})
.then(() => {
this.createName = "";
this.updatePage();
})
.catch(error => {
this.axiosReqestError(
"Creating Category",
error.response.data.message
);
});
},
previousPage() {
Expand Down
8 changes: 5 additions & 3 deletions client/src/views/Dataset.vue
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ export default {
queryAnnotated() {
let showAnnotated = this.panel.showAnnotated;
let showNotAnnotated = this.panel.showNotAnnotated;
if (showAnnotated && showNotAnnotated) return null
if (showAnnotated && showNotAnnotated) return null;
if (!showAnnotated && !showNotAnnotated) return " ";
return showAnnotated;
Expand Down Expand Up @@ -446,7 +446,9 @@ export default {
}
},
watch: {
queryAnnotated() { this.updatePage() },
queryAnnotated() {
this.updatePage();
},
folders() {
this.updatePage();
},
Expand Down

0 comments on commit f479768

Please sign in to comment.