Skip to content

Commit

Permalink
upstream: b=master,r=eafdd59328222f7829cb98f42a67e3315d4a08a2,t=2019-…
Browse files Browse the repository at this point in the history
…01-06-1232-49871
  • Loading branch information
sonatype-zion committed Jan 7, 2019
1 parent 34ec772 commit 13a2f9c
Show file tree
Hide file tree
Showing 30 changed files with 849 additions and 82 deletions.
27 changes: 27 additions & 0 deletions buildsupport/testing/jasmine/Mocks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/

var TestClasses = {};

var Ext = {
define: function(className, implementationObject) {
TestClasses[className] = implementationObject;
}
};

function MockComponent(properties) {
this.properties = properties;
}
MockComponent.prototype.get = function(propertyName) {
return this.properties[propertyName];
};
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
@import 'NX/view/feature/NotVisible';
@import 'NX/view/dev/Panel';
@import 'NX/view/info/Entry';
@import 'NX/view/info/DependencySnippetPanel';
@import 'NX/view/drilldown/Actions';
@import 'NX/view/drilldown/Details';
@import 'NX/view/drilldown/Drilldown';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/**
* @class NX.view.info.DependencySnippetPanel
*/

.nx-info-dependency-snippet-panel {
.description {
color: $color-charcoal;
margin: 10px 2px 0 2px;
}
.snippet-text {
background-color: $color-light-smoke;
margin: 5px 0 0 0;
overflow: auto;
padding: 10px 5px;
width: 100%;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,12 @@ Ext.define('NX.app.PluginStrings', {
// SearchBoxTip
SearchBoxTip_ExactMatch: 'Use <b>""</b> for exact match - "example"',
SearchBoxTip_Wildcard: 'Use <b>*</b> for wildcard - exampl*',
SearchBoxTip_LearnMore: 'Learn more...'
SearchBoxTip_LearnMore: 'Learn more...',

// DependencySnippet Panel
DependencySnippetPanel_Title: 'Usage',
DependencySnippetPanel_Copy_Button_Tooltip: 'Copy snippet to clipboard'

}
}, function(obj) {
NX.I18n.register(obj);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,45 +32,34 @@ Ext.define('NX.controller.DependencySnippet', {
],

/**
* Add a new dependency snippet
* Add a new dependency snippet generator
*
* @public
*/
addDependencySnippet: function(format, snippet) {
var store = this.getStore('DependencySnippet');

if (Array.isArray(snippet)) {
snippet.forEach(function(element) {
store.add({format: format, displayName: element.displayName, snippetTemplate: element.snippetTemplate});
})
}
else {
store.add({format: format, displayName: snippet.displayName, snippetTemplate: snippet.snippetTemplate});
}
addDependencySnippetGenerator: function(format, snippetGenerator) {
this.getStore('DependencySnippet').add({
format: format,
snippetGenerator: snippetGenerator
});
},

/**
* Retrieve dependency snippet for a given component and format
* Retrieve dependency snippets for a given format, component and asset.
* Leave assetModel undefined if requesting snippets for a component.
*
* @public
*/
findDependencySnippets: function(format, componentModel) {
getDependencySnippets: function(format, componentModel, assetModel) {
var store = this.getStore('DependencySnippet');
var dependencySnippets = [];

return store.queryRecordsBy(function(record) {
store.queryRecordsBy(function(record) {
return format === record.get('format');
}).map(function(record) {
var snippetTemplate = record.get('snippetTemplate');
if (!(snippetTemplate instanceof Ext.XTemplate)) {
record.set('snippetTemplate', Ext.create('Ext.XTemplate', snippetTemplate));
record.commit();
}
return record;
}).map(function(record) {
return {
displayName: record.get('displayName'),
snippetText: record.get('snippetTemplate').apply(componentModel)
}
}).forEach(function(record) {
var snippets = record.get('snippetGenerator')(componentModel, assetModel);
Array.prototype.push.apply(dependencySnippets, snippets);
});

return dependencySnippets;
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Ext.define('NX.model.DependencySnippet', {

fields: [
{ name: 'format', type: 'string' },
{ name: 'displayName', type: 'string' },
{ name: 'snippetTemplate', type: 'auto' }
{ name: 'snippetGenerator', type: 'auto' }
]
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
/*global Ext, NX*/

/**
* Clipboard related utils.
*
* @since 3.next
*/
Ext.define('NX.util.Clipboard', {
singleton: true,

/**
* Copy specified text to clipboard
*
* @public
* @param {String} text
*/
copyToClipboard: function(text) {
var textarea;
if (navigator.clipboard) {
navigator.clipboard.writeText(text);
} else if (window.clipboardData && window.clipboardData.setData) {
window.clipboardData.setData("Text", text);
} else {
textarea = document.createElement("textarea");
textarea.value = text;
textarea.style.position = 'fixed';
textarea.style.left = '-99999px';
textarea.style.height = '1em';
textarea.style.width = '1em';
document.body.appendChild(textarea);
textarea.select();

try {
document.execCommand('copy');
} catch (err) {
console.error('Unable to copy text to clipboard: ', err);
}

document.body.removeChild(textarea);
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
/*
* Sonatype Nexus (TM) Open Source Version
* Copyright (c) 2008-present Sonatype, Inc.
* All rights reserved. Includes the third-party code listed at http://links.sonatype.com/products/nexus/oss/attributions.
*
* This program and the accompanying materials are made available under the terms of the Eclipse Public License Version 1.0,
* which accompanies this distribution and is available at http://www.eclipse.org/legal/epl-v10.html.
*
* Sonatype Nexus (TM) Professional Version is available from Sonatype, Inc. "Sonatype" and "Sonatype Nexus" are trademarks
* of Sonatype, Inc. Apache Maven is a trademark of the Apache Software Foundation. M2eclipse is a trademark of the
* Eclipse Foundation. All other trademarks are the property of their respective owners.
*/
/*global Ext*/

/**
* Dependency snippet info panel.
*
* @since 3.next
*/
Ext.define('NX.view.info.DependencySnippetPanel', {
extend: 'Ext.panel.Panel',
alias: 'widget.nx-info-dependency-snippet-panel',

requires: [
'NX.I18n',
'NX.util.Clipboard'
],

cls: 'nx-info-dependency-snippet-panel',

framed: true,
scrollable: true,
header: false,

/**
* @private
*/
initComponent: function() {
this.items = {
xtype: 'panel',
ui: 'nx-inset',
title: NX.I18n.get('DependencySnippetPanel_Title'),
collapsible: this.collapsible === undefined ? true : this.collapsible,

items: {
xtype: 'panel',
ui: 'nx-subsection',
frame: true,
layout: 'vbox',
items: [
{
xtype: 'container',
layout: 'hbox',
flex: 1,
height: "auto",
width: "100%",
items: [
{
xtype: 'combo',
name: 'toolCombo',
editable: false,
store: [],
queryMode: 'local',
flex: 1,
listeners: {
change: this.showSnippetText.bind(this)
}
}, {
xtype: 'button',
margin: '0 0 0 24px',
tooltip: NX.I18n.get('DependencySnippetPanel_Copy_Button_Tooltip'),
glyph: 'xf0c5@FontAwesome' /* fa-copy */,
listeners: {
click: this.onCopyClick.bind(this)
}
}
]
}, {
xtype: 'component',
name: 'snippet',
editable: false,
layout: 'vbox',
flex: 2,
tpl: '<p class="description">{description}</p>' +
'<pre class="snippet-text">{snippetText}</pre>',
data: {text: ''},
width: "100%"
}
]
}
};

this.callParent();
},

getSnippetComponent: function() {
return this.down('component[name="snippet"]');
},

getStorageKey: function(format) {
return 'dependency-snippet-panel-' + format + '-tool-displayName';
},

getToolComboBox: function() {
return this.down('combo[name="toolCombo"]');
},

setDependencySnippets: function(format, dependencySnippets) {
var storedDisplayName = Ext.state.Manager.get(this.getStorageKey(format)),
toolCombo = this.getToolComboBox();

this.format = format;
this.dependencySnippetMap = {};

if (dependencySnippets && dependencySnippets.length > 0) {
dependencySnippets.forEach(function(snippet) {
this.dependencySnippetMap[snippet.displayName] = {
snippetText: snippet.snippetText,
description: snippet.description
};
}, this);
this.updateSnippetDisplayNames(dependencySnippets);
if (storedDisplayName && toolCombo.store.findRecord("field1", storedDisplayName)) {
this.selectSnippet(storedDisplayName);
} else {
this.selectSnippet(dependencySnippets[0].displayName);
}
} else {
toolCombo.setStore([]);
this.getSnippetComponent().update({
snippetText: '',
description: ''
});
}
},

selectSnippet: function(displayName) {
var toolCombo = this.getToolComboBox(),
toolComboSelection = toolCombo.getSelection(),
selectedDisplayName = toolComboSelection && toolComboSelection.get('field1');

if (selectedDisplayName === displayName) {
// change event won't get fired so explicitly trigger text update
this.showSnippetText(toolCombo, displayName);
} else {
toolCombo.select(displayName);
}
},

showSnippetText: function(toolCombo, selectedDisplayName) {
var snippet = this.dependencySnippetMap[selectedDisplayName];

if (snippet) {
this.getSnippetComponent().update({
snippetText: Ext.htmlEncode(snippet.snippetText),
description: Ext.htmlEncode(snippet.description)
});
Ext.state.Manager.set(this.getStorageKey(this.format), selectedDisplayName);
}
},

updateSnippetDisplayNames: function(dependencySnippets) {
var toolCombo = this.getToolComboBox(),
displayNames = dependencySnippets.map(function(snippet) {
return snippet.displayName;
});

toolCombo.setStore(displayNames);
},

onCopyClick: function() {
var text = this.getSnippetComponent().getData().snippetText;
NX.util.Clipboard.copyToClipboard(Ext.htmlDecode(text));
}
});
Original file line number Diff line number Diff line change
Expand Up @@ -8658,6 +8658,22 @@ fieldset.nx-form-section.nx-no-title {
margin: 0;
}

.nx-info-dependency-snippet-panel .description {
/**
* @class NX.view.info.DependencySnippetPanel
*/
color: #444;
margin: 10px 2px 0 2px;
}

.nx-info-dependency-snippet-panel .snippet-text {
background-color: #f4f4f4;
margin: 5px 0 0 0;
overflow: auto;
padding: 10px 5px;
width: 100%;
}

.nx-actions {
/**
* @class NX.view.drilldown.Actions
Expand Down

Large diffs are not rendered by default.

Loading

0 comments on commit 13a2f9c

Please sign in to comment.