mirror of
https://github.com/simon987/sist2.git
synced 2025-12-15 08:19:06 +00:00
Option to update media type tab in real time, add media type table in details
This commit is contained in:
@@ -7,40 +7,24 @@ import InspireTree from "inspire-tree";
|
||||
import InspireTreeDOM from "inspire-tree-dom";
|
||||
|
||||
import "inspire-tree-dom/dist/inspire-tree-light.min.css";
|
||||
import {getSelectedTreeNodes} from "@/util";
|
||||
import {getSelectedTreeNodes, getTreeNodeAttributes} from "@/util";
|
||||
import Sist2Api from "@/Sist2Api";
|
||||
import Sist2Query from "@/Sist2Query";
|
||||
|
||||
export default {
|
||||
name: "MimePicker",
|
||||
data() {
|
||||
return {
|
||||
mimeTree: null,
|
||||
stashedMimeTreeAttributes: null
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.$store.subscribe((mutation) => {
|
||||
if (mutation.type === "setUiMimeMap") {
|
||||
const mimeMap = mutation.payload.slice();
|
||||
|
||||
const elem = document.getElementById("mimeTree");
|
||||
console.log(elem);
|
||||
|
||||
this.mimeTree = new InspireTree({
|
||||
selection: {
|
||||
mode: 'checkbox'
|
||||
},
|
||||
data: mimeMap
|
||||
});
|
||||
new InspireTreeDOM(this.mimeTree, {
|
||||
target: '#mimeTree'
|
||||
});
|
||||
this.mimeTree.on("node.state.changed", this.handleTreeClick);
|
||||
this.mimeTree.deselect();
|
||||
|
||||
if (this.$store.state._onLoadSelectedMimeTypes.length > 0) {
|
||||
this.$store.state._onLoadSelectedMimeTypes.forEach(mime => {
|
||||
this.mimeTree.node(mime).select();
|
||||
});
|
||||
}
|
||||
if (mutation.type === "setUiMimeMap" && this.mimeTree === null) {
|
||||
this.initializeTree();
|
||||
} else if (mutation.type === "busSearch") {
|
||||
this.updateTree();
|
||||
}
|
||||
});
|
||||
},
|
||||
@@ -52,6 +36,73 @@ export default {
|
||||
|
||||
this.$store.commit("setSelectedMimeTypes", getSelectedTreeNodes(this.mimeTree));
|
||||
},
|
||||
updateTree() {
|
||||
|
||||
if (this.$store.getters.optUpdateMimeMap === false) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.stashedMimeTreeAttributes === null) {
|
||||
this.stashedMimeTreeAttributes = getTreeNodeAttributes(this.mimeTree);
|
||||
}
|
||||
|
||||
const query = Sist2Query.searchQuery();
|
||||
|
||||
Sist2Api.getMimeTypes(query).then(({buckets, mimeMap}) => {
|
||||
this.$store.commit("setUiMimeMap", mimeMap);
|
||||
this.$store.commit("setUiDetailsMimeAgg", buckets);
|
||||
|
||||
this.mimeTree.removeAll();
|
||||
this.mimeTree.addNodes(mimeMap);
|
||||
|
||||
// Restore selected mimes
|
||||
if (this.stashedMimeTreeAttributes === null) {
|
||||
// NOTE: This happens when successive fast searches are triggered
|
||||
this.stashedMimeTreeAttributes = {};
|
||||
// Always add the selected mime types
|
||||
this.$store.state.selectedMimeTypes.forEach(mime => {
|
||||
this.stashedMimeTreeAttributes[mime] = {
|
||||
checked: true
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Object.entries(this.stashedMimeTreeAttributes).forEach(([mime, attributes]) => {
|
||||
if (this.mimeTree.node(mime)) {
|
||||
if (attributes.checked) {
|
||||
this.mimeTree.node(mime).select();
|
||||
}
|
||||
if (attributes.collapsed === false) {
|
||||
this.mimeTree.node(mime).expand();
|
||||
}
|
||||
}
|
||||
});
|
||||
this.stashedMimeTreeAttributes = null;
|
||||
});
|
||||
},
|
||||
|
||||
initializeTree() {
|
||||
const mimeMap = this.$store.state.uiMimeMap;
|
||||
|
||||
this.mimeTree = new InspireTree({
|
||||
selection: {
|
||||
mode: "checkbox"
|
||||
},
|
||||
data: mimeMap
|
||||
});
|
||||
|
||||
new InspireTreeDOM(this.mimeTree, {
|
||||
target: "#mimeTree"
|
||||
});
|
||||
this.mimeTree.on("node.state.changed", this.handleTreeClick);
|
||||
this.mimeTree.deselect();
|
||||
|
||||
if (this.$store.state._onLoadSelectedMimeTypes.length > 0) {
|
||||
this.$store.state._onLoadSelectedMimeTypes.forEach(mime => {
|
||||
this.mimeTree.node(mime).select();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user