Upgraded to API v2

This commit is contained in:
Joel Collins 2019-11-26 14:32:22 +00:00
parent fce7d2ee93
commit a33329b77d
2 changed files with 37 additions and 30 deletions

View file

@ -44,7 +44,7 @@
</div> </div>
<div class="uk-card-footer uk-padding-small"> <div class="uk-card-footer uk-padding-small">
<div v-for="tag in captureState.metadata.tags" :key="tag"> <div v-for="tag in tags" :key="tag" class="uk-display-inline">
<span <span
v-if="tag === 'temporary'" v-if="tag === 'temporary'"
class="uk-label uk-label-danger uk-margin-small-right" class="uk-label uk-label-danger uk-margin-small-right"
@ -166,20 +166,20 @@ export default {
return "#" + this.metadataModalID; return "#" + this.metadataModalID;
}, },
thumbURL: function() { thumbURL: function() {
return this.captureURL + "/download?thumbnail=true"; return `${this.$store.getters.baseUri}${
this.captureState.links.download
}?thumbnail=true`;
}, },
imgURL: function() { imgURL: function() {
return this.captureURL + "/download/" + this.fileName; return `${this.$store.getters.baseUri}${
this.captureState.links.download
}`;
}, },
tagURL: function() { tagsURL: function() {
return this.captureURL + "/tags"; return `${this.$store.getters.baseUri}${this.captureState.links.tags}`;
}, },
captureURL: function() { captureURL: function() {
return ( return `${this.$store.getters.baseUri}${this.captureState.links.self}`;
this.$store.getters.uri +
"/camera/capture/" +
this.captureState.metadata.id
);
}, },
betterTimestring: function() { betterTimestring: function() {
var dtSplit = this.captureState.metadata.time.split("_"); var dtSplit = this.captureState.metadata.time.split("_");
@ -195,8 +195,6 @@ export default {
methods: { methods: {
handleTagSubmit: function(event) { handleTagSubmit: function(event) {
console.log(this.tagURL);
console.log(this.newtag);
this.newTagRequest(this.newtag); this.newTagRequest(this.newtag);
this.newtag = ""; this.newtag = "";
UIkit.modal(event.target.parentNode).hide(); // TODO: Remove somehow UIkit.modal(event.target.parentNode).hide(); // TODO: Remove somehow
@ -225,7 +223,7 @@ export default {
newTagRequest: function(tag_string) { newTagRequest: function(tag_string) {
// Send tag PUT request // Send tag PUT request
axios axios
.put(this.tagURL, [tag_string]) .put(this.tagsURL, [tag_string])
.then(() => { .then(() => {
// Update tag array // Update tag array
this.getTagRequest(); this.getTagRequest();
@ -246,7 +244,7 @@ export default {
console.log(tag_string); console.log(tag_string);
// Send tag DELETE request // Send tag DELETE request
axios axios
.delete(this.tagURL, { data: [tag_string] }) .delete(this.tagsURL, { data: [tag_string] })
.then(() => { .then(() => {
// Update tag array // Update tag array
this.getTagRequest(); this.getTagRequest();
@ -259,9 +257,9 @@ export default {
getTagRequest: function() { getTagRequest: function() {
// Send tag request // Send tag request
axios axios
.get(this.tagURL) .get(this.tagsURL)
.then(response => { .then(response => {
this.tags = response.data.metadata.tags; this.tags = response.data;
}) })
.catch(error => { .catch(error => {
this.modalError(error); // Let mixin handle error this.modalError(error); // Let mixin handle error

View file

@ -103,7 +103,7 @@ export default {
data: function() { data: function() {
return { return {
captureList: [], captures: {},
checkedTags: [], checkedTags: [],
sortDescending: true, sortDescending: true,
galleryFolder: "", galleryFolder: "",
@ -112,10 +112,13 @@ export default {
}, },
computed: { computed: {
captureApiUri: function() { capturesUri: function() {
return this.$store.getters.uri + "/camera/capture"; return `${this.$store.getters.baseUri}/api/v2/captures`;
},
captureList: function() {
// List of captures, obtained from this.captures values
return Object.values(this.captures);
}, },
allTags: function() { allTags: function() {
// Return an array of unique tags across all captures // Return an array of unique tags across all captures
var tags = []; var tags = [];
@ -130,6 +133,7 @@ export default {
}, },
noScanCaptureList: function() { noScanCaptureList: function() {
// List of captures that are not part of a scan
var captures = []; var captures = [];
for (var capture of this.captureList) { for (var capture of this.captureList) {
// Filter by selected tags // Filter by selected tags
@ -145,7 +149,7 @@ export default {
}, },
allScans: function() { allScans: function() {
// Return an array of unique tags across all captures // List of scans as capture-like objects
var scans = {}; var scans = {};
for (var capture of this.captureList) { for (var capture of this.captureList) {
@ -187,12 +191,11 @@ export default {
} }
// Create a preview thumbnail // Create a preview thumbnail
// TODO: Use URI defined in capture representation
if (!("thumbnail" in scans[id])) { if (!("thumbnail" in scans[id])) {
scans[id].thumbnail = scans[id].thumbnail = `${this.$store.getters.baseUri}${
this.$store.getters.uri + capture.links.download
"/camera/capture/" + }?thumbnail=true`;
capture.metadata.id +
"/download?thumbnail=true";
} }
} }
} }
@ -200,10 +203,14 @@ export default {
}, },
scanList: function() { scanList: function() {
// List of scans, obtained from this.allScans values
return Object.values(this.allScans); return Object.values(this.allScans);
}, },
itemList: function() { itemList: function() {
// Get list of current items to show
// If galleryFolder (ie inside a scan folder), show scan captures
// Otherwise, show root captures and scan cards
if (this.galleryFolder) { if (this.galleryFolder) {
console.log(this.allScans[this.galleryFolder].captureList); console.log(this.allScans[this.galleryFolder].captureList);
return this.allScans[this.galleryFolder].captureList; return this.allScans[this.galleryFolder].captureList;
@ -213,10 +220,12 @@ export default {
}, },
filteredItems: function() { filteredItems: function() {
// Filter itemList by checkedTags
return this.filterCaptureList(this.itemList, this.checkedTags); return this.filterCaptureList(this.itemList, this.checkedTags);
}, },
sortedItems: function() { sortedItems: function() {
// Sort filteredItems using sortCaptureList function
return this.sortCaptureList(this.filteredItems); return this.sortCaptureList(this.filteredItems);
} }
}, },
@ -235,12 +244,10 @@ export default {
methods: { methods: {
updateCaptureList: function() { updateCaptureList: function() {
console.log("Updating capture list..."); console.log("Updating capture list...");
// Send move request
axios axios
.get(this.captureApiUri) .get(this.capturesUri)
.then(response => { .then(response => {
this.$store.dispatch("updateState"); // Update store state for good measure this.captures = response.data;
this.captureList = response.data; // Update boxes from response
}) })
.catch(error => { .catch(error => {
this.modalError(error); // Let mixin handle error this.modalError(error); // Let mixin handle error
@ -248,6 +255,7 @@ export default {
}, },
filterCaptureList: function(list, filterTags) { filterCaptureList: function(list, filterTags) {
// Filter a list of captures by an array of tags
var result = []; var result = [];
for (var capture of list) { for (var capture of list) {
// Assume exclusion // Assume exclusion
@ -269,6 +277,7 @@ export default {
}, },
sortCaptureList: function(list) { sortCaptureList: function(list) {
// Sort a list of captures by metadata time
function compare(a, b) { function compare(a, b) {
if (a.metadata.time < b.metadata.time) return -1; if (a.metadata.time < b.metadata.time) return -1;
if (a.metadata.time > b.metadata.time) return 1; if (a.metadata.time > b.metadata.time) return 1;