Skip to content

Commit

Permalink
feat: Preview tabs for workspaces (#172)
Browse files Browse the repository at this point in the history
  • Loading branch information
csmig authored Mar 1, 2021
1 parent c1fa69b commit 07fcfe2
Show file tree
Hide file tree
Showing 17 changed files with 293 additions and 1,141 deletions.
2 changes: 1 addition & 1 deletion clients/extjs/js/SM/Ajax.js
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ Ext.lib.Ajax = function() {
if (o) {
// Keycloak token handling, carl.a.smigielski@saic.com
window.keycloak.updateToken(10).then(function (refreshed) {
console.info("updateToken() returned successfully, refreshed: " + refreshed)
// console.info("updateToken() returned successfully, refreshed: " + refreshed)
o.conn.open(method, uri, true);
if (window.keycloak.token) {
initHeader('Authorization', 'Bearer ' + window.keycloak.token)
Expand Down
73 changes: 31 additions & 42 deletions clients/extjs/js/SM/Collection.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,35 @@
'use strict'

class Collection {
constructor (api) {
this.config = config
this.infoUi = config.infoUi || {}
this.assetUi = config.assetUi || {}
this.grantUi = config.grantUi || {}
this.stigUi = config.stignUi || {}
async function addOrUpdateCollection( collectionId, collectionObj, options ) {
try {
let url, method
if (collectionId) {
url = `${STIGMAN.Env.apiBase}/collections/${collectionId}?elevate=${options.elevate}`
method = 'PUT'
}
else {
url = `${STIGMAN.Env.apiBase}/collections?elevate=${options.elevate}`,
method = 'POST'
}
let result = await Ext.Ajax.requestPromise({
url: url,
method: method,
headers: { 'Content-Type': 'application/json;charset=utf-8' },
params: {
projection: ['owners', 'statistics']
},
jsonData: collectionObj
})
let apiCollection = JSON.parse(result.response.responseText)
// Refresh the curUser global
await SM.GetUserObject()

let event = collectionId ? 'collectionchanged' : 'collectioncreated'
SM.Dispatcher.fireEvent( event, apiCollection, options )
}


async updateBackend(putData) {
try {
let result = await Ext.Ajax.requestPromise({
url: `${CMSAT.Env.apiBase}/collections/${this.config.collectionId}`,
method: 'PUT',
headers: { 'Content-Type': 'application/json;charset=utf-8' },
jsonData: putData
})
this.config = JSON.parse(result.response.responseText)
return result
}
catch (err) {
throw (err)
}
}

async deleteCollection() {
try {
let results = await Ext.Ajax.requestPromise({
url: `${CMSAT.Env.apiBase}/collections/${this.config.collectionId}`,
method: 'DELETE'
})
return results
}
catch (err) {
throw (err)
}
}

updateInfoUi () {
this.infoUi.panel.update(this.config)
catch (e) {
alert (e.message)
}

}
}


8 changes: 7 additions & 1 deletion clients/extjs/js/SM/MainPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SM.MainTabPanel = Ext.extend(Ext.TabPanel, {
}
}
const config = {
plugins: new Ext.ux.TabCloseOnMiddleClick(),
plugins: new SM.TabEnhancements(),
title: 'STIGManager',
enableTabScroll: true,
activeTab: 0,
Expand All @@ -53,6 +53,12 @@ SM.MainTabPanel = Ext.extend(Ext.TabPanel, {
}
}
}
},
tabchange: function (tp, tab) {
// expand the navigation tree to the source node
if (tab.sm_treePath) {
Ext.getCmp('app-nav-tree').selectPath(tab.sm_treePath)
}
}
},
items: []
Expand Down
86 changes: 70 additions & 16 deletions clients/extjs/js/SM/NavTree.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,17 +319,17 @@ SM.AppNavTree = Ext.extend(Ext.tree.TreePanel, {
listeners: {
click: me.treeClick,
render: this.treeRender,
beforeexpandnode: function (n) {
collapsenode: function (n) {
n.loaded = false; // always reload from the server
}
}
}

this.onCollectionCreated = function (apiCollection) {
this.onCollectionCreated = function (apiCollection, options) {
const collectionGrant = curUser.collectionGrants.find( g => g.collection.collectionId === apiCollection.collectionId )
if (collectionGrant) {
let collectionRoot = me.getNodeById('collections-root')
collectionRoot.appendChild( SM.CollectionNodeConfig( apiCollection ) )
let newNode = collectionRoot.appendChild( SM.CollectionNodeConfig( apiCollection ) )
function sortFn (a, b) {
if (a.attributes.id === 'collection-create-leaf') {
return -1
Expand All @@ -346,6 +346,13 @@ SM.AppNavTree = Ext.extend(Ext.tree.TreePanel, {
return 0
}
collectionRoot.sort(sortFn)
if (options.showManager) {
me.selectPath(`${newNode.getPath()}${me.pathSeparator}${newNode.attributes.children[0].id}`, undefined, (bSuccess, oSelNode) => {
if (bSuccess) {
oSelNode.getUI().elNode.click()
}
})
}
}
}

Expand Down Expand Up @@ -696,33 +703,63 @@ SM.AppNavTree = Ext.extend(Ext.tree.TreePanel, {
Ext.Msg.alert('Status', 'AJAX request failed in loadTree()');
}
},
treeClick: function (n) {
var idAppend;
var tab;

treeClick: function (n, e) {
let idAppend;
let tab;
if (!n.leaf) {
return
}
console.log(`in treeClick() with ${e.type}`)
if (n.attributes.report == 'review') {
idAppend = '-' + n.attributes.assetId + '-' + n.attributes.benchmarkId.replace(".", "_");
tab = Ext.getCmp('main-tab-panel').getItem('reviewTab' + idAppend);
if (tab) {
// Detect double click
if (e.browserEvent.detail === 2) {
tab.makePermanent()
}
tab.show();
} else {
addReview(n.attributes);
addReview({
leaf: n.attributes,
treePath: n.getPath()
})
}
}
if (n.attributes.report == 'collection-review') {
idAppend = '-' + n.attributes.collectionId + '-' + n.attributes.benchmarkId.replace(".", "_");
tab = Ext.getCmp('main-tab-panel').getItem('collection-review-tab' + idAppend);
if (tab) {
// Detect double click
if (e.browserEvent.detail === 2) {
tab.makePermanent()
}
tab.show();
} else {
addCollectionReview(n.attributes);
addCollectionReview({
leaf: n.attributes,
treePath: n.getPath()
})
}
}
if (n.attributes.action == 'import') {
uploadArchive(n);
}
if (n.attributes.action == 'findings') {
addFindingsSummary(n.attributes.collectionId, n.attributes.collectionName);
tab = Ext.getCmp('main-tab-panel').getItem('findingsTab-' + n.attributes.collectionId)
if (tab) {
// Detect double click
if (e.browserEvent.detail === 2) {
tab.makePermanent()
}
tab.show()
} else {
addFindingsSummary({
collectionId: n.attributes.collectionId,
collectionName: n.attributes.collectionName,
treePath: n.getPath()
})
}
}
if (n.attributes.action == 'collection-create') {
let collectionRootNode = n.parentNode
Expand Down Expand Up @@ -772,24 +809,41 @@ SM.AppNavTree = Ext.extend(Ext.tree.TreePanel, {
}

if (n.attributes.action == 'collection-management') {
addCollectionManager(n.attributes.collectionId, n.attributes.collectionName)
addCollectionManager({
collectionId: n.attributes.collectionId,
collectionName: n.attributes.collectionName,
treePath: n.getPath()
})
}
if (n.attributes.action == 'collection-status') {
addCompletionStatus(n.attributes.collectionId, n.attributes.collectionName)
tab = Ext.getCmp('main-tab-panel').getItem('completionTab-' + n.attributes.collectionId)
if (tab) {
// Detect double click
if (e.browserEvent.detail === 2) {
tab.makePermanent()
}
tab.show()
} else {
addCompletionStatus({
collectionId: n.attributes.collectionId,
collectionName: n.attributes.collectionName,
treePath: n.getPath()
})
}
}

switch (n.id) {
case 'collection-admin':
addCollectionAdmin();
addCollectionAdmin( { treePath: n.getPath() } );
break;
case 'user-admin':
addUserAdmin();
addUserAdmin( { treePath: n.getPath() });
break;
case 'stig-admin':
addStigAdmin();
addStigAdmin( { treePath: n.getPath() });
break;
case 'appdata-admin':
addAppDataAdmin();
addAppDataAdmin( { treePath: n.getPath() });
break;
case 'wo-admin':
doWo();
Expand Down
4 changes: 3 additions & 1 deletion clients/extjs/js/appDataAdmin.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
function addAppDataAdmin() {
function addAppDataAdmin( params ) {
let { treePath } = params
const tab = Ext.getCmp('main-tab-panel').getItem('appdata-admin-tab')
if (tab) {
tab.show()
Expand Down Expand Up @@ -205,6 +206,7 @@ function addAppDataAdmin() {

const thisTab = Ext.getCmp('main-tab-panel').add({
id: 'appdata-admin-tab',
sm_treePath: treePath,
iconCls: 'sm-database-save-icon',
title: 'Application Data',
closable: true,
Expand Down
14 changes: 11 additions & 3 deletions clients/extjs/js/collectionAdmin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
function addCollectionAdmin() {

function addCollectionAdmin( params ) {
let { treePath } = params
const tab = Ext.getCmp('main-tab-panel').getItem('collection-admin-tab')
if (tab) {
tab.show()
Expand Down Expand Up @@ -270,12 +270,20 @@ function addCollectionAdmin() {

const thisTab = Ext.getCmp('main-tab-panel').add({
id: 'collection-admin-tab',
sm_treePath: treePath,
iconCls: 'sm-collection-icon',
title: 'Collections',
closable: true,
layout: 'border',
border: false,
items: [collectionGrid]
items: [collectionGrid],
listeners: {
beforedestroy: function () {
SM.Dispatcher.removeListener('collectionchanged', onCollectionChanged)
SM.Dispatcher.removeListener('collectioncreated', onCollectionCreated)
SM.Dispatcher.removeListener('collectiondeleted', onCollectionDeleted)
}
}
})
thisTab.show()

Expand Down
28 changes: 23 additions & 5 deletions clients/extjs/js/collectionManager.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
async function addCollectionManager( collectionId, collectionName ) {
async function addCollectionManager( params ) {
let { collectionId, collectionName, treePath } = params
try {
const tab = Ext.getCmp('main-tab-panel').getItem(`${collectionId}-collection-manager-tab`)
if (tab) {
Expand Down Expand Up @@ -77,6 +78,8 @@ async function addCollectionManager( collectionId, collectionName ) {
collectionId: collectionId,
collectionName: collectionName,
iconCls: 'sm-collection-tab-icon',
sm_tabMode: 'permanent',
sm_treePath: treePath,
closable: true,
layout: 'border',
layoutConfig: {
Expand Down Expand Up @@ -127,12 +130,27 @@ async function addCollectionManager( collectionId, collectionName ) {
assetGrid.getStore().reload()
}
managerTab.updateTitle = function () {
this.setTitle(`${this.collectionName} : Configuration`)
managerTab.setTitle(`${managerTab.sm_tabMode === 'ephemeral' ? '<i>':''}${managerTab.collectionName} / Manage${this.sm_tabMode === 'ephemeral' ? '</i>':''}`)
}
let thisTab = Ext.getCmp('main-tab-panel').add(managerTab)
managerTab.updateTitle.call(managerTab)
thisTab.show();

managerTab.makePermanent = function () {
managerTab.sm_tabMode = 'permanent'
managerTab.updateTitle.call(managerTab)
}

let tp = Ext.getCmp('main-tab-panel')
let ephTabIndex = tp.items.findIndex('sm_tabMode', 'ephemeral')
let thisTab
if (ephTabIndex !== -1) {
let ephTab = tp.items.itemAt(ephTabIndex)
tp.remove(ephTab)
thisTab = tp.insert(ephTabIndex, managerTab);
} else {
thisTab = tp.add( managerTab )
}
thisTab.updateTitle.call(thisTab)
thisTab.show();

let result = await Ext.Ajax.requestPromise({
url: `${STIGMAN.Env.apiBase}/collections/${collectionId}`,
params: {
Expand Down
Loading

0 comments on commit 07fcfe2

Please sign in to comment.