Skip to content

Commit

Permalink
Fixes #15054: Manage technique resource in technique editor using a f…
Browse files Browse the repository at this point in the history
…ile manager
  • Loading branch information
VinceMacBuche committed Jun 11, 2019
1 parent b468360 commit 0a5308c
Show file tree
Hide file tree
Showing 5 changed files with 141 additions and 9 deletions.
10 changes: 9 additions & 1 deletion builder/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,15 @@ <h3 id="technique-name">{{originalTechnique.name}} <span ng-hide="originalTechni
<i class="glyphicon" ng-class="{'glyphicon-chevron-down': parameter_open, 'glyphicon-chevron-right': !parameter_open}"></i>
Resources
</uib-accordion-heading>
<button class="btn" ng-click="openEditor = !openEditor">open the bidule</button> {{openEditor}}

<div class="form-group col-sm-12 no-padding-right" ng-repeat="resource in selectedTechnique.resources track by $index">
<div class="input-group col-sm-12">
<input type="text" class="form-control" readonly ng-model="resource.name" >
<span class="input-group-addon">Use with:</span>
<input readonly class="form-control" ng-model="'${resources_dir}/'+ resource.name + ' - ' + resource.state " placeHolder="Value in methods">
</div>
</div>
<button class="btn" ng-click="openEditor = !openEditor">open file editor</button>
<div ng-if="openEditor">
<angular-filemanager></angular-filemanager>
</div>
Expand Down
2 changes: 1 addition & 1 deletion builder/js/angular-filemanager-1.5.1.min.js

Large diffs are not rendered by default.

134 changes: 127 additions & 7 deletions builder/js/ncf.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ app.directive('popover', function() {
});

// Declare controller ncf-builder
app.controller('ncf-builder', function ($scope, $uibModal, $http, $log, $location, $anchorScroll, ngToast, $timeout, focus, fileManagerConfig, apiMiddleware, fileNavigator) {
app.controller('ncf-builder', function ($scope, $uibModal, $http, $q, $location, $anchorScroll, ngToast, $timeout, focus, fileManagerConfig, apiMiddleware, apiHandler, $window) {
initScroll();
console.log($scope.$$childHead);
console.log($scope);
Expand Down Expand Up @@ -321,16 +321,133 @@ function defineMethodClassContext (method_call) {
}
}
}
function updateResources() {
var resourceUrl = '/rudder/secure/api/ncf/' + $scope.selectedTechnique.bundle_name +"/" + $scope.selectedTechnique.version +"/resources"

$http.get(resourceUrl).then(
function(response) {
console.log(response.data.data.resources)
$scope.selectedTechnique.resources = response.data.data.resources
}
, function(response) {
console.log(response)
}
)
}
function updateFileManagerConf () {

var newUrl = "/rudder/secure/api/resourceExplorer/"+ $scope.selectedTechnique.bundle_name +"/" + $scope.selectedTechnique.version

updateResources()

apiHandler.prototype.deferredHandler = function(data, deferred, code, defaultMsg) {
updateResources()

if (!data || typeof data !== 'object') {
this.error = 'Error %s - Bridge response error, please check the API docs or this ajax response.'.replace('%s', code);
}
if (code == 404) {
this.error = 'Error 404 - Backend bridge is not working, please check the ajax response.';
}
if (data.result && data.result.error) {
this.error = data.result.error;
}
if (!this.error && data.error) {
this.error = data.error.message;
}
if (!this.error && defaultMsg) {
this.error = defaultMsg;
}
if (this.error) {
return deferred.reject(data);
}
return deferred.resolve(data);
};
console.log(newUrl)
console.log("Hello!!" + $scope.selectedTechnique.name )
apiMiddleware.prototype.list = function(path, customDeferredHandler) {
console.log("Hello!!" + $scope.selectedTechnique.name )
return this.apiHandler.list(fileManagerConfig.listUrl + $scope.selectedTechnique.bundle_name +"/" + $scope.selectedTechnique.version +"/resources" , this.getPath(path), customDeferredHandler);
return this.apiHandler.list(newUrl, this.getPath(path), customDeferredHandler);
};
}

apiMiddleware.prototype.upload = function(files, path) {
if (! $window.FormData) {
throw new Error('Unsupported browser version');
}

var destination = this.getPath(path);

return this.apiHandler.upload(newUrl, destination, files);
};


apiMiddleware.prototype.createFolder = function(item) {
var path = item.tempModel.fullPath();
return this.apiHandler.createFolder(newUrl, path);
};
apiMiddleware.prototype.getContent = function(item) {
var itemPath = this.getFilePath(item);
return this.apiHandler.getContent(newUrl, itemPath);
};

apiMiddleware.prototype.rename = function(item) {
var itemPath = this.getFilePath(item);
var newPath = item.tempModel.fullPath();

return this.apiHandler.rename(newUrl, itemPath, newPath);
};

apiMiddleware.prototype.remove = function(files) {
console.log(files)
var items = this.getFileList(files);
return this.apiHandler.remove(newUrl, items);
};
apiMiddleware.prototype.edit = function(item) {
var itemPath = this.getFilePath(item);
return this.apiHandler.edit(newUrl, itemPath, item.tempModel.content);
};


apiMiddleware.prototype.copy = function(files, path) {
var items = this.getFileList(files);
var singleFilename = items.length === 1 ? files[0].tempModel.name : undefined;
return this.apiHandler.copy(newUrl, items, this.getPath(path), singleFilename);
};

apiMiddleware.prototype.changePermissions = function(files, dataItem) {
var items = this.getFileList(files);
var code = dataItem.tempModel.perms.toCode();
var octal = dataItem.tempModel.perms.toOctal();
var recursive = !!dataItem.tempModel.recursive;

return this.apiHandler.changePermissions(newUrl, items, code, octal, recursive);
};


apiMiddleware.prototype.move = function(files, path) {
var items = this.getFileList(files);
return this.apiHandler.move(newUrl, items, this.getPath(path));
};


apiMiddleware.prototype.download = function(item, forceNewWindow) {
//TODO: add spinner to indicate file is downloading
var itemPath = this.getFilePath(item);
var toFilename = item.model.name;

if (item.isFolder()) {
return;
}

return this.apiHandler.download(
newUrl,
itemPath,
toFilename,
fileManagerConfig.downloadFilesByAjax,
forceNewWindow
);
};
}
// Transform a ncf technique into a valid UI technique
// Add original_index to the method call, so we can track their modification on index
// Handle classes so we split them into OS classes (the first one only) and advanced classes
Expand Down Expand Up @@ -419,6 +536,7 @@ $scope.getSessionStorage = function(){
$scope.originalTechnique = existingTechnique;
if (doSave) {
$scope.selectedTechnique = angular.copy($scope.originalTechnique);
updateFileManagerConf();
$scope.resetFlags();
}else{
$scope.keepChanges();
Expand Down Expand Up @@ -1204,6 +1322,8 @@ $scope.onImportFileChange = function (fileEl) {
// We will lose the link between the selected method and the technique, to prevent unintended behavior, close the edit method panel
$scope.selectedMethod = undefined;
}

updateResources();
$scope.resetFlags();
}

Expand Down Expand Up @@ -1399,16 +1519,13 @@ app.config(function($httpProvider,$locationProvider) {
//Allows the browser to indicate to the cache to retrieve the GET request content from the original server rather than sending one he must keep.
$httpProvider.defaults.headers.get['Pragma'] = 'no-cache';
});
console.log("ca m'énerve!")



app.config(['fileManagerConfigProvider', function (config) {
var apiPath = '/rudder/secure/api/ncf/';
var defaults = config.$get();

config.set({
appName : 'ncf',
appName : 'resources',
listUrl : apiPath,
uploadUrl : apiPath,
renameUrl : apiPath,
Expand All @@ -1423,10 +1540,13 @@ app.config(['fileManagerConfigProvider', function (config) {
compressUrl : apiPath,
extractUrl : apiPath,
permissionsUrl : apiPath,
isEditableFilePattern : /.*/,
//tplPath : baseUrl + '/templates/angular/filemanager',
allowedActions: angular.extend(defaults.allowedActions, {
compress: false,
compressChooseName: false,
preview : true,
edit: true,
extract: false
})
});
Expand Down
2 changes: 2 additions & 0 deletions tests/unit/technique_metadata_test_content.cf
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

bundle agent content_escaping_test
{
vars:
"resources_dir" string => "${this.promise_dir}/resources";
methods:
"Install a package with correct version_context_0" usebundle => _method_reporting_context("Install a package with correct version", "apache2");
"Install a package with correct version" usebundle => package_install_version("apache2", "2.2.11"),
Expand Down
2 changes: 2 additions & 0 deletions tools/ncf.py
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,8 @@ def generate_technique_content(technique, methods):
content.append('{')


content.append(' vars:')
content.append(' "resources_dir" string => "${this.promise_dir}/resources";')
content.append(' methods:')

# Handle method calls
Expand Down

0 comments on commit 0a5308c

Please sign in to comment.