diff --git a/frontend/src/business/components/common/head/HeaderOrgWs.vue b/frontend/src/business/components/common/head/HeaderOrgWs.vue
index 35bdad37be..7a88e5947c 100644
--- a/frontend/src/business/components/common/head/HeaderOrgWs.vue
+++ b/frontend/src/business/components/common/head/HeaderOrgWs.vue
@@ -2,25 +2,41 @@
@@ -34,107 +50,170 @@ import {
ROLE_TEST_VIEWER,
WORKSPACE_ID
} from '../../../../common/js/constants';
- import {getCurrentUser, hasRoles, saveLocalStorage} from "../../../../common/js/utils";
+import {getCurrentUser, hasRoles, saveLocalStorage} from "../../../../common/js/utils";
- export default {
- name: "MsHeaderOrgWs",
- created() {
- this.initMenuData();
- this.getCurrentUserInfo();
- },
- data() {
- return {
- organizationList: [
- {name: this.$t('organization.none')},
- ],
- workspaceList: [
- {name: this.$t('workspace.none')},
- ],
- currentUserInfo: {},
- currentUserId: getCurrentUser().id,
- workspaceIds: [],
- currentOrganizationName: '',
- currentWorkspaceName: ''
- }
- },
- computed: {
- currentUser: () => {
- return getCurrentUser();
- }
- },
- methods: {
- initMenuData() {
- if (hasRoles(ROLE_ORG_ADMIN, ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
- this.$get("/organization/list/userorg/" + encodeURIComponent(this.currentUserId), response => {
- let data = response.data;
- this.organizationList = data;
- let org = data.filter(r => r.id === this.currentUser.lastOrganizationId);
- if (org.length > 0) {
- this.currentOrganizationName = org[0].name;
- }
- });
- }
- if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
- if (!this.currentUser.lastOrganizationId) {
- return false;
- }
- this.$get("/workspace/list/orgworkspace/", response => {
- let data = response.data;
- if (data.length === 0) {
- this.workspaceList = [{name: this.$t('workspace.none')}]
- } else {
- this.workspaceList = data;
- let workspace = data.filter(r => r.id === this.currentUser.lastWorkspaceId);
- if (workspace.length > 0) {
- this.currentWorkspaceName = workspace[0].name;
- localStorage.setItem(WORKSPACE_ID, workspace[0].id);
- }
- }
- })
- }
- },
- getCurrentUserInfo() {
- this.$get("/user/info/" + encodeURIComponent(this.currentUserId), response => {
- this.currentUserInfo = response.data;
- })
- },
- changeOrg(data) {
- let orgId = data.id;
- if (!orgId) {
- return false;
- }
- this.$post("/user/switch/source/org/" + orgId, {}, response => {
- saveLocalStorage(response);
- if (response.data.workspaceId) {
- localStorage.setItem("workspace_id", response.data.workspaceId);
- }
- localStorage.removeItem(PROJECT_ID);
- this.$router.push('/').then(() => {
- window.location.reload();
- }).catch(err => err);
- });
- },
- changeWs(data) {
- let workspaceId = data.id;
- if (!workspaceId) {
- return false;
- }
- this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
- saveLocalStorage(response);
- localStorage.setItem("workspace_id", workspaceId);
- localStorage.removeItem(PROJECT_ID);
- this.$router.push('/').then(() => {
- window.location.reload();
- }).catch(err => err);
- })
- }
+export default {
+ name: "MsHeaderOrgWs",
+ created() {
+ this.initMenuData();
+ this.getCurrentUserInfo();
+ },
+ data() {
+ return {
+ organizationList: [
+ {name: this.$t('organization.none')},
+ ],
+ workspaceList: [
+ {name: this.$t('workspace.none')},
+ ],
+ currentUserInfo: {},
+ currentUserId: getCurrentUser().id,
+ workspaceIds: [],
+ currentOrganizationName: '',
+ currentWorkspaceName: '',
+ searchOrg: '',
+ searchWs: '',
+ orgListCopy: [{name: this.$t('organization.none')}],
+ wsListCopy: [{name: this.$t('workspace.none')}]
}
+ },
+ computed: {
+ currentUser: () => {
+ return getCurrentUser();
+ }
+ },
+ watch: {
+ searchOrg(val) {
+ this.query('org', val);
+ },
+ searchWs(val) {
+ this.query('ws', val);
+ }
+ },
+ methods: {
+ initMenuData() {
+ if (hasRoles(ROLE_ORG_ADMIN, ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
+ this.$get("/organization/list/userorg/" + encodeURIComponent(this.currentUserId), response => {
+ let data = response.data;
+ this.organizationList = data;
+ this.orgListCopy = data;
+ let org = data.filter(r => r.id === this.currentUser.lastOrganizationId);
+ if (org.length > 0) {
+ this.currentOrganizationName = org[0].name;
+ }
+ });
+ }
+ if (hasRoles(ROLE_TEST_VIEWER, ROLE_TEST_USER, ROLE_TEST_MANAGER)) {
+ if (!this.currentUser.lastOrganizationId) {
+ return false;
+ }
+ this.$get("/workspace/list/orgworkspace/", response => {
+ let data = response.data;
+ if (data.length === 0) {
+ this.workspaceList = [{name: this.$t('workspace.none')}]
+ } else {
+ this.workspaceList = data;
+ this.wsListCopy = data;
+ let workspace = data.filter(r => r.id === this.currentUser.lastWorkspaceId);
+ if (workspace.length > 0) {
+ this.currentWorkspaceName = workspace[0].name;
+ localStorage.setItem(WORKSPACE_ID, workspace[0].id);
+ }
+ }
+ })
+ }
+ },
+ getCurrentUserInfo() {
+ this.$get("/user/info/" + encodeURIComponent(this.currentUserId), response => {
+ this.currentUserInfo = response.data;
+ })
+ },
+ changeOrg(data) {
+ let orgId = data.id;
+ if (!orgId) {
+ return false;
+ }
+ this.$post("/user/switch/source/org/" + orgId, {}, response => {
+ saveLocalStorage(response);
+ if (response.data.workspaceId) {
+ localStorage.setItem("workspace_id", response.data.workspaceId);
+ }
+ localStorage.removeItem(PROJECT_ID);
+ this.$router.push('/').then(() => {
+ window.location.reload();
+ }).catch(err => err);
+ });
+ },
+ changeWs(data) {
+ let workspaceId = data.id;
+ if (!workspaceId) {
+ return false;
+ }
+ this.$post("/user/switch/source/ws/" + workspaceId, {}, response => {
+ saveLocalStorage(response);
+ localStorage.setItem("workspace_id", workspaceId);
+ localStorage.removeItem(PROJECT_ID);
+ this.$router.push('/').then(() => {
+ window.location.reload();
+ }).catch(err => err);
+ })
+ },
+ query(sign, queryString) {
+ if (sign === 'org') {
+ this.organizationList = queryString ? this.orgListCopy.filter(this.createFilter(queryString)) : this.orgListCopy;
+ }
+ if (sign === 'ws') {
+ this.workspaceList = queryString ? this.wsListCopy.filter(this.createFilter(queryString)) : this.wsListCopy;
+ }
+ },
+ createFilter(queryString) {
+ return item => {
+ return (item.name.toLowerCase().indexOf(queryString.toLowerCase()) !== -1);
+ };
+ },
}
+}