Newer
Older
<template>
<div>
<div v-if="!isSearching"
class="studip-tree" :class="{'studip-tree-navigatable': showStructureAsNavigation}">
<studip-progress-indicator v-if="isLoading" :size="48"></studip-progress-indicator>
<studip-tree-list v-if="viewType === 'list' && startNode" :with-children="withChildren"
:visible-children-only="visibleChildrenOnly"
:with-courses="withCourses" :semester="semester" :sem-class="semClass" :node="startNode"
:breadcrumb-icon="breadcrumbIcon" :editable="editable" :edit-url="editUrl"
:create-url="createUrl" :delete-url="deleteUrl" :with-export="withExport"
:show-structure-as-navigation="showStructureAsNavigation" :assignable="assignable"
:with-course-assign="withCourseAssign"
@change-current-node="changeCurrentNode"></studip-tree-list>
<studip-tree-table v-else-if="viewType === 'table' && startNode" :with-children="withChildren"
:visible-children-only="visibleChildrenOnly"
:with-courses="withCourses" :semester="semester" :sem-class="semClass" :node="startNode"
:breadcrumb-icon="breadcrumbIcon" :editable="editable" :edit-url="editUrl"
:create-url="createUrl" :delete-url="deleteUrl" :with-export="withExport"
:show-structure-as-navigation="showStructureAsNavigation" :assignable="assignable"
:with-course-assign="withCourseAssign"
@change-current-node="changeCurrentNode"></studip-tree-table>
<studip-tree-node v-else-if="viewType === 'tree' && startNode" :with-info="withInfo"
:visible-children-only="visibleChildrenOnly" :node="startNode"
:open-levels="openLevels" :openNodes="openNodes" :breadcrumb-icon="breadcrumbIcon"
:editable="editable" :edit-url="editUrl" :create-url="createUrl" :delete-url="deleteUrl"
:assignable="assignable" :assign-leaves-only="assignLeavesOnly"
:not-assignable-nodes="notAssignableNodes"></studip-tree-node>
</div>
<div v-else class="studip-tree">
<tree-search-result :search-config="searchConfig"></tree-search-result>
</div>
<MountingPortal v-if="withSearch" mountTo="#search-widget" name="sidebar-search">
<search-widget v-if="currentNode" :min-length="3" ref="searchWidget"></search-widget>

Thomas Hackl
committed
<MountingPortal v-if="!editable && !isSearching && !isLoading && currentNode"
mountTo="#views-widget"
name="sidebar-views">
<studip-tree-view-widget :config="viewConfig" />
</MountingPortal>
</div>
</template>
<script>
import axios from 'axios';
import { TreeMixin } from '../../mixins/TreeMixin';

Thomas Hackl
committed
import PageLayout from '../../../assets/javascripts/lib/page_layout';
import StudipProgressIndicator from '../StudipProgressIndicator.vue';
import SearchWidget from '../SearchWidget.vue';

Thomas Hackl
committed
import StudipTreeViewWidget from './StudipTreeViewWidget.vue';
import StudipTreeList from './StudipTreeList.vue';
import StudipTreeTable from './StudipTreeTable.vue';
import StudipTreeNode from './StudipTreeNode.vue';
import TreeSearchResult from './TreeSearchResult.vue';
export default {
name: 'StudipTree',
components: {

Thomas Hackl
committed
TreeSearchResult,
SearchWidget,
StudipTreeViewWidget,
StudipProgressIndicator,
StudipTreeList,
StudipTreeTable,
StudipTreeNode
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
},
mixins: [ TreeMixin ],
props: {
viewType: {
type: String,
default: 'tree'
},
treeId: {
type: String,
default: ''
},
startId: {
type: String,
required: true
},
title: {
type: String,
default: ''
},
openNodes: {
type: Array,
default: () => []
},
openLevels: {
type: Number,
default: 0
},
withChildren: {
type: Boolean,
default: true
},
withInfo: {
type: Boolean,
default: true
},
visibleChildrenOnly: {
type: Boolean,
default: true
},
withCourses: {
type: Boolean,
default: false
},
semester: {
type: String,
default: ''
},
semClass: {
type: Number,
default: 0
},
breadcrumbIcon: {
type: String,
default: 'literature'
},
itemIcon: {
type: String,
default: 'literature'
},
withSearch: {
type: Boolean,
default: false
},
withExport: {
type: Boolean,
default: false
},
withCourseAssign: {
type: Boolean,
default: false
},
editable: {
type: Boolean,
default: false
},
editUrl: {
type: String,
default: ''
},
createUrl: {
type: String,
default: ''
},
deleteUrl: {
type: String,
default: ''
},
showStructureAsNavigation: {
type: Boolean,
default: false
},
assignable: {
type: Boolean,
default: false
},
assignLeavesOnly: {
type: Boolean,
default: false
},
notAssignableNodes: {
type: Array,
default: () => []
}
},
data() {
return {
nodeId: this.startId,
startNode: null,
currentNode: this.startNode,
loaded: false,
isLoading: false,
showStructuralNavigation: false,
searchConfig: {},

Thomas Hackl
committed
isSearching: false,

Thomas Hackl
committed
viewConfig: null,
pageTitle: document.title
}
},
methods: {
changeCurrentNode(node) {
this.currentNode = node;

Thomas Hackl
committed
this.viewConfig = {
view: this.viewType,
node: this.currentNode,
semester: this.semester,
semClass: this.semClass
};

Thomas Hackl
committed
this.setPageTitle(this.currentNode.attributes.name);
this.$nextTick(() => {
document.getElementById('tree-breadcrumb-' + node.attributes.id)?.focus();
});
},
exportUrl() {
return STUDIP.URLHelper.getURL('dispatch.php/tree/export_csv');
},
injectSearchterm(targetId, searchterm) {
const form = document.getElementById(targetId).querySelector('form');
let input = form.querySelector('input[type="hidden"][name="search"]');
if (!input) {
input = document.createElement('input');
input.setAttribute('id', `${targetId}-searchterm`);
input.setAttribute('type', 'hidden');
input.setAttribute('name', 'search');
form.appendChild(input);
}
input.setAttribute('value', searchterm);

Thomas Hackl
committed
},
setPageTitle(nodeTitle) {
const title = this.pageTitle.split('-');
PageLayout.title = title.slice(0, -1).join('-') + '/ ' + nodeTitle + ' -' + title[title.length - 1];
}
},
mounted() {
window.focus();
const loadingIndicator = axios.interceptors.request.use(config => {
setTimeout(() => {
if (!this.loaded) {
this.isLoading = true;
}
}, this.showProgressIndicatorTimeout);
return config;
});
this.getNode(this.startId).then(response => {
this.startNode = response.data.data;
this.currentNode = this.startNode;
this.loaded = true;
this.isLoading = false;

Thomas Hackl
committed
this.viewConfig = {
view: this.viewType,
node: this.currentNode,
semester: this.semester,
semClass: this.semClass
};

Thomas Hackl
committed
this.setPageTitle(this.currentNode.attributes.name);
});
axios.interceptors.request.eject(loadingIndicator);
this.globalOn('do-search', searchterm => {

Thomas Hackl
committed
this.searchConfig = {
searchterm,
semester: this.semester,
semclass: this.semClass,

Thomas Hackl
committed
classname: this.startNode.attributes.classname,
startId: this.currentNode.id,
};
this.injectSearchterm('semester-selector', searchterm);
this.injectSearchterm('semclass-selector', searchterm);
this.isSearching = true;
});
this.globalOn('cancel-search', () => {
this.searchConfig = {};
this.searchterm = '';
document.getElementById('semester-selector-searchterm')?.remove();
document.getElementById('semclass-selector-searchterm')?.remove();
this.isSearching = false;
});
}
}
</script>