|
@@ -35,7 +35,7 @@
|
|
<script>
|
|
<script>
|
|
export default {
|
|
export default {
|
|
name: "paginated-media",
|
|
name: "paginated-media",
|
|
- props: ['rows', 'width', 'inline', 'deletable', 'current'],
|
|
|
|
|
|
+ props: ['rows', 'width', 'inline', 'deletable', 'current', 'filter'],
|
|
mounted: function () {
|
|
mounted: function () {
|
|
window.addEventListener('resize', this.resize);
|
|
window.addEventListener('resize', this.resize);
|
|
window.addEventListener('wheel', this.scroll);
|
|
window.addEventListener('wheel', this.scroll);
|
|
@@ -57,7 +57,11 @@ export default {
|
|
resizeEvent: false,
|
|
resizeEvent: false,
|
|
page: 1,
|
|
page: 1,
|
|
pageCount: 1,
|
|
pageCount: 1,
|
|
- images: []
|
|
|
|
|
|
+ images: [],
|
|
|
|
+ elements: {
|
|
|
|
+ previous: null,
|
|
|
|
+ next: null
|
|
|
|
+ }
|
|
}
|
|
}
|
|
},
|
|
},
|
|
methods: {
|
|
methods: {
|
|
@@ -78,7 +82,7 @@ export default {
|
|
}, 500);
|
|
}, 500);
|
|
},
|
|
},
|
|
change: function (file) {
|
|
change: function (file) {
|
|
- if (file['project_id'] === this.$root.project.identifier)
|
|
|
|
|
|
+ if (file.project_id === this.$root.project.identifier)
|
|
this.get();
|
|
this.get();
|
|
},
|
|
},
|
|
deleteElement: function (element) {
|
|
deleteElement: function (element) {
|
|
@@ -96,6 +100,14 @@ export default {
|
|
|
|
|
|
this.get(callback);
|
|
this.get(callback);
|
|
},
|
|
},
|
|
|
|
+ prevElement: function () {
|
|
|
|
+ if (this.elements.previous)
|
|
|
|
+ this.$emit('click', this.elements.previous);
|
|
|
|
+ },
|
|
|
|
+ nextElement: function () {
|
|
|
|
+ if (this.elements.next)
|
|
|
|
+ this.$emit('click', this.elements.next);
|
|
|
|
+ },
|
|
get: function (callback) {
|
|
get: function (callback) {
|
|
// get container size
|
|
// get container size
|
|
const width = this.$refs.media.offsetWidth;
|
|
const width = this.$refs.media.offsetWidth;
|
|
@@ -112,13 +124,25 @@ export default {
|
|
this.$refs.media.style.gridTemplateRows = `repeat(${rows}, ${elementHeight}px)`;
|
|
this.$refs.media.style.gridTemplateRows = `repeat(${rows}, ${elementHeight}px)`;
|
|
|
|
|
|
// receive elements
|
|
// receive elements
|
|
|
|
+ if (this.page === 0)
|
|
|
|
+ this.page = 1;
|
|
|
|
+
|
|
const limit = rows * cols;
|
|
const limit = rows * cols;
|
|
- const offset = (this.page === 0 ? 0 : this.page - 1) * limit;
|
|
|
|
|
|
+ const offset = (this.page - 1) * limit;
|
|
|
|
|
|
const requestWidth = Math.ceil(elementWidth / 200) * 200;
|
|
const requestWidth = Math.ceil(elementWidth / 200) * 200;
|
|
const requestHeight = Math.ceil(elementHeight / 200) * 200;
|
|
const requestHeight = Math.ceil(elementHeight / 200) * 200;
|
|
|
|
|
|
- this.$root.socket.get(`/projects/${this.$root.project.identifier}/data/${offset}/${limit}`)
|
|
|
|
|
|
+ let url;
|
|
|
|
+ if (this.filter === undefined || this.filter === false)
|
|
|
|
+ url = `/projects/${this.$root.project.identifier}/data/${offset}/${limit}`;
|
|
|
|
+ else if (this.filter === null)
|
|
|
|
+ url = `/projects/${this.$root.project.identifier}/data/0/${offset}/${limit}`;
|
|
|
|
+ else
|
|
|
|
+ url = `/projects/${this.$root.project.identifier}/data/${this.filter}/${offset}/${limit}`;
|
|
|
|
+
|
|
|
|
+ // call endpoint
|
|
|
|
+ this.$root.socket.get(url)
|
|
.then(response => response.json())
|
|
.then(response => response.json())
|
|
.then(elements => {
|
|
.then(elements => {
|
|
this.images = elements.files;
|
|
this.images = elements.files;
|
|
@@ -128,7 +152,7 @@ export default {
|
|
image.src = this.$root.socket.media(image, requestWidth, requestHeight);
|
|
image.src = this.$root.socket.media(image, requestWidth, requestHeight);
|
|
}
|
|
}
|
|
|
|
|
|
- if (this.page > this.pageCount) {
|
|
|
|
|
|
+ if (this.pageCount > 0 && this.page > this.pageCount) {
|
|
this.page = this.pageCount;
|
|
this.page = this.pageCount;
|
|
return this.get(callback);
|
|
return this.get(callback);
|
|
}
|
|
}
|
|
@@ -160,10 +184,40 @@ export default {
|
|
},
|
|
},
|
|
watch: {
|
|
watch: {
|
|
current: function (newVal) {
|
|
current: function (newVal) {
|
|
- if (!newVal)
|
|
|
|
|
|
+ if (!newVal) {
|
|
|
|
+ this.elements.previous = false;
|
|
|
|
+ this.elements.next = false;
|
|
|
|
+ this.$emit('hasPreviousElement', false);
|
|
|
|
+ this.$emit('hasNextElement', false);
|
|
return;
|
|
return;
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ // find current in list
|
|
this.findCurrent();
|
|
this.findCurrent();
|
|
|
|
+
|
|
|
|
+ // receive previous and next element
|
|
|
|
+ this.$root.socket.get(`/data/${this.current.identifier}/previous_next`)
|
|
|
|
+ .then(response => response.json())
|
|
|
|
+ .then(data => {
|
|
|
|
+ if (this.filter === undefined || this.filter === false) {
|
|
|
|
+ this.elements.previous = data.previous;
|
|
|
|
+ this.elements.next = data.next;
|
|
|
|
+ } else {
|
|
|
|
+ this.elements.previous = data.previousInCollection;
|
|
|
|
+ this.elements.next = data.nextInCollection;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ this.$emit('hasPreviousElement', this.elements.previous);
|
|
|
|
+ this.$emit('hasNextElement', this.elements.next);
|
|
|
|
+ });
|
|
|
|
+ },
|
|
|
|
+ filter: function () {
|
|
|
|
+ this.get(() => {
|
|
|
|
+ if (this.images.length === 0)
|
|
|
|
+ this.$emit('click', false);
|
|
|
|
+ else
|
|
|
|
+ this.$emit('click', this.images[0]);
|
|
|
|
+ });
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|