1
0
Fork 0
mirror of https://github.com/portainer/portainer.git synced 2025-08-02 20:35:25 +02:00

chore(project): add prettier for code format (#3645)

* chore(project): install prettier and lint-staged

* chore(project): apply prettier to html too

* chore(project): git ignore eslintcache

* chore(project): add a comment about format script

* chore(prettier): update printWidth

* chore(prettier): remove useTabs option

* chore(prettier): add HTML validation

* refactor(prettier): fix closing tags

* feat(prettier): define angular parser for html templates

* style(prettier): run prettier on codebase

Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>
This commit is contained in:
Chaim Lev-Ari 2020-04-11 00:54:53 +03:00 committed by GitHub
parent 6663073be1
commit cf5056d9c0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
714 changed files with 31228 additions and 28305 deletions

View file

@ -4,7 +4,7 @@ angular.module('portainer.agent').controller('FileUploaderController', [
var ctrl = this;
ctrl.state = {
uploadInProgress: false
uploadInProgress: false,
};
ctrl.onFileSelected = onFileSelected;
@ -19,5 +19,5 @@ angular.module('portainer.agent').controller('FileUploaderController', [
ctrl.state.uploadInProgress = false;
});
}
}
},
]);

View file

@ -1,6 +1,3 @@
<button
ngf-select="$ctrl.onFileSelected($file)"
class="btn ng-scope"
button-spinner="$ctrl.state.uploadInProgress">
<i style="margin:0" class="fa fa-upload" ng-if="!$ctrl.state.uploadInProgress"></i>
<button ngf-select="$ctrl.onFileSelected($file)" class="btn ng-scope" button-spinner="$ctrl.state.uploadInProgress">
<i style="margin: 0;" class="fa fa-upload" ng-if="!$ctrl.state.uploadInProgress"></i>
</button>

View file

@ -2,6 +2,6 @@ angular.module('portainer.agent').component('fileUploader', {
templateUrl: './file-uploader.html',
controller: 'FileUploaderController',
bindings: {
uploadFile: '<onFileSelected'
}
uploadFile: '<onFileSelected',
},
});

View file

@ -1,14 +1,20 @@
<div class="datatable">
<rd-widget>
<rd-widget-header icon="{{$ctrl.titleIcon}}" title-text="{{ $ctrl.titleText }}">
<file-uploader authorization="DockerAgentBrowsePut" ng-if="$ctrl.isUploadAllowed" on-file-selected="$ctrl.onFileSelectedForUpload">
</file-uploader>
<rd-widget-header icon="{{ $ctrl.titleIcon }}" title-text="{{ $ctrl.titleText }}">
<file-uploader authorization="DockerAgentBrowsePut" ng-if="$ctrl.isUploadAllowed" on-file-selected="($ctrl.onFileSelectedForUpload)"> </file-uploader>
</rd-widget-header>
<rd-widget-body classes="no-padding">
<div class="searchBar">
<i class="fa fa-search searchIcon" aria-hidden="true"></i>
<input type="text" class="searchInput" ng-model="$ctrl.state.textFilter" ng-model-options="{ debounce: 300 }"
ng-change="$ctrl.onTextFilterChange()" placeholder="Search..." auto-focus>
<input
type="text"
class="searchInput"
ng-model="$ctrl.state.textFilter"
ng-model-options="{ debounce: 300 }"
ng-change="$ctrl.onTextFilterChange()"
placeholder="Search..."
auto-focus
/>
</div>
<div class="table-responsive">
<table class="table">
@ -43,36 +49,33 @@
<tbody>
<tr ng-if="!$ctrl.isRoot">
<td colspan="4">
<a ng-click="$ctrl.goToParent()"><i class="fa fa-level-up-alt space-right"></i>Go
to parent</a>
<a ng-click="$ctrl.goToParent()"><i class="fa fa-level-up-alt space-right"></i>Go to parent</a>
</td>
</tr>
<tr ng-repeat="item in ($ctrl.state.filteredDataSet = ($ctrl.dataset | filter:$ctrl.state.textFilter | orderBy:$ctrl.state.orderBy:$ctrl.state.reverseOrder))">
<td>
<span ng-if="item.edit">
<input class="input-sm" type="text" ng-model="item.newName"
on-enter-key="$ctrl.rename({name: item.Name, newName: item.newName}); item.edit = false;"
auto-focus />
<input
class="input-sm"
type="text"
ng-model="item.newName"
on-enter-key="$ctrl.rename({ name: item.Name, newName: item.newName }); item.edit = false"
auto-focus
/>
<a class="interactive" ng-click="item.edit = false;"><i class="fa fa-times"></i></a>
<a class="interactive" ng-click="$ctrl.rename({name: item.Name, newName: item.newName}); item.edit = false;"><i
class="fa fa-check-square"></i></a>
<a class="interactive" ng-click="$ctrl.rename({name: item.Name, newName: item.newName}); item.edit = false;"><i class="fa fa-check-square"></i></a>
</span>
<span ng-if="!item.edit && item.Dir">
<a ng-click="$ctrl.browse({name: item.Name})"><i class="fa fa-folder space-right"
aria-hidden="true"></i>{{ item.Name }}</a>
</span>
<span ng-if="!item.edit && !item.Dir">
<i class="fa fa-file space-right" aria-hidden="true"></i>{{
item.Name }}
<a ng-click="$ctrl.browse({name: item.Name})"><i class="fa fa-folder space-right" aria-hidden="true"></i>{{ item.Name }}</a>
</span>
<span ng-if="!item.edit && !item.Dir"> <i class="fa fa-file space-right" aria-hidden="true"></i>{{ item.Name }} </span>
</td>
<td>{{ item.Size | humansize }}</td>
<td>
{{ item.ModTime | getisodatefromtimestamp }}
</td>
<td>
<btn authorization="DockerAgentBrowseGet" class="btn btn-xs btn-primary space-right" ng-click="$ctrl.download({ name: item.Name })"
ng-if="!item.Dir">
<btn authorization="DockerAgentBrowseGet" class="btn btn-xs btn-primary space-right" ng-click="$ctrl.download({ name: item.Name })" ng-if="!item.Dir">
<i class="fa fa-download" aria-hidden="true"></i> Download
</btn>
<btn authorization="DockerAgentBrowseRename" class="btn btn-xs btn-primary space-right" ng-click="item.newName = item.Name; item.edit = true">
@ -94,4 +97,4 @@
</div>
</rd-widget-body>
</rd-widget>
</div>
</div>

View file

@ -15,8 +15,8 @@ angular.module('portainer.agent').component('filesDatatable', {
rename: '&',
download: '&',
delete: '&',
isUploadAllowed: '<',
onFileSelectedForUpload: '<'
}
onFileSelectedForUpload: '<',
},
});

View file

@ -1,12 +1,15 @@
import _ from 'lodash-es';
angular.module('portainer.agent').controller('HostBrowserController', [
'HostBrowserService', 'Notifications', 'FileSaver', 'ModalService',
'HostBrowserService',
'Notifications',
'FileSaver',
'ModalService',
function HostBrowserController(HostBrowserService, Notifications, FileSaver, ModalService) {
var ctrl = this;
var ROOT_PATH = '/host';
ctrl.state = {
path: ROOT_PATH
path: ROOT_PATH,
};
ctrl.goToParent = goToParent;
@ -21,7 +24,7 @@ angular.module('portainer.agent').controller('HostBrowserController', [
function getRelativePath(path) {
path = path || ctrl.state.path;
var rootPathRegex = new RegExp('^' + ROOT_PATH + '\/?');
var rootPathRegex = new RegExp('^' + ROOT_PATH + '/?');
var relativePath = path.replace(rootPathRegex, '/');
return relativePath;
}
@ -71,7 +74,7 @@ angular.module('portainer.agent').controller('HostBrowserController', [
HostBrowserService.get(filePath)
.then(function onFileReceived(data) {
var downloadData = new Blob([data.file], {
type: 'text/plain;charset=utf-8'
type: 'text/plain;charset=utf-8',
});
FileSaver.saveAs(downloadData, file);
})
@ -83,15 +86,12 @@ angular.module('portainer.agent').controller('HostBrowserController', [
function confirmDeleteFile(name) {
var filePath = buildPath(ctrl.state.path, name);
ModalService.confirmDeletion(
'Are you sure that you want to delete ' + getRelativePath(filePath) + ' ?',
function onConfirm(confirmed) {
if (!confirmed) {
return;
}
return deleteFile(filePath);
ModalService.confirmDeletion('Are you sure that you want to delete ' + getRelativePath(filePath) + ' ?', function onConfirm(confirmed) {
if (!confirmed) {
return;
}
);
return deleteFile(filePath);
});
}
function deleteFile(path) {
@ -145,5 +145,5 @@ angular.module('portainer.agent').controller('HostBrowserController', [
function refreshList() {
getFilesForPath(ctrl.state.path);
}
}
},
]);

View file

@ -1,6 +1,8 @@
<files-datatable
title-text="Host browser - {{$ctrl.getRelativePath()}}" title-icon="fa-file"
dataset="$ctrl.files" table-key="host_browser"
title-text="Host browser - {{ $ctrl.getRelativePath() }}"
title-icon="fa-file"
dataset="$ctrl.files"
table-key="host_browser"
order-by="Dir"
is-root="$ctrl.isRoot()"
go-to-parent="$ctrl.goToParent()"
@ -8,9 +10,7 @@
rename="$ctrl.renameFile(name, newName)"
download="$ctrl.downloadFile(name)"
delete="$ctrl.deleteFile(name)"
is-upload-allowed="true"
on-file-selected-for-upload="$ctrl.onFileSelectedForUpload"
on-file-selected-for-upload="($ctrl.onFileSelectedForUpload)"
>
</files-datatable>

View file

@ -1,5 +1,5 @@
angular.module('portainer.agent').component('hostBrowser', {
controller: 'HostBrowserController',
templateUrl: './host-browser.html',
bindings: {}
bindings: {},
});

View file

@ -2,6 +2,6 @@ angular.module('portainer.agent').component('nodeSelector', {
templateUrl: './nodeSelector.html',
controller: 'NodeSelectorController',
bindings: {
model: '='
}
model: '=',
},
});

View file

@ -1,8 +1,6 @@
<div class="form-group">
<label for="target_node" class="col-sm-1 control-label text-left">Node</label>
<div class="col-sm-11">
<select class="form-control"
ng-model="$ctrl.model" ng-options="agent.NodeName as agent.NodeName for agent in $ctrl.agents"
></select>
<select class="form-control" ng-model="$ctrl.model" ng-options="agent.NodeName as agent.NodeName for agent in $ctrl.agents"></select>
</div>
</div>

View file

@ -1,18 +1,20 @@
angular.module('portainer.agent')
.controller('NodeSelectorController', ['AgentService', 'Notifications', function (AgentService, Notifications) {
var ctrl = this;
angular.module('portainer.agent').controller('NodeSelectorController', [
'AgentService',
'Notifications',
function (AgentService, Notifications) {
var ctrl = this;
this.$onInit = function() {
AgentService.agents()
.then(function success(data) {
ctrl.agents = data;
if (!ctrl.model) {
ctrl.model = data[0].NodeName;
}
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to load agents');
});
};
}]);
this.$onInit = function () {
AgentService.agents()
.then(function success(data) {
ctrl.agents = data;
if (!ctrl.model) {
ctrl.model = data[0].NodeName;
}
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to load agents');
});
};
},
]);

View file

@ -4,6 +4,6 @@ angular.module('portainer.agent').component('volumeBrowser', {
bindings: {
volumeId: '<',
nodeName: '<',
isUploadEnabled: '<'
}
isUploadEnabled: '<',
},
});

View file

@ -1,6 +1,8 @@
<files-datatable
title-text="Volume browser" title-icon="fa-file"
dataset="$ctrl.files" table-key="volume_browser"
title-text="Volume browser"
title-icon="fa-file"
dataset="$ctrl.files"
table-key="volume_browser"
order-by="Dir"
is-root="$ctrl.state.path === '/'"
go-to-parent="$ctrl.up()"
@ -8,7 +10,6 @@
rename="$ctrl.rename(name, newName)"
download="$ctrl.download(name)"
delete="$ctrl.delete(name)"
is-upload-allowed="$ctrl.isUploadEnabled"
on-file-selected-for-upload="$ctrl.onFileSelectedForUpload"
on-file-selected-for-upload="($ctrl.onFileSelectedForUpload)"
></files-datatable>

View file

@ -1,137 +1,137 @@
import _ from 'lodash-es';
angular.module('portainer.agent')
.controller('VolumeBrowserController', ['HttpRequestHelper', 'VolumeBrowserService', 'FileSaver', 'Blob', 'ModalService', 'Notifications',
function (HttpRequestHelper, VolumeBrowserService, FileSaver, Blob, ModalService, Notifications) {
var ctrl = this;
angular.module('portainer.agent').controller('VolumeBrowserController', [
'HttpRequestHelper',
'VolumeBrowserService',
'FileSaver',
'Blob',
'ModalService',
'Notifications',
function (HttpRequestHelper, VolumeBrowserService, FileSaver, Blob, ModalService, Notifications) {
var ctrl = this;
this.state = {
path: '/'
};
this.state = {
path: '/',
};
this.rename = function(file, newName) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
var newFilePath = this.state.path === '/' ? newName : this.state.path + '/' + newName;
this.rename = function (file, newName) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
var newFilePath = this.state.path === '/' ? newName : this.state.path + '/' + newName;
VolumeBrowserService.rename(this.volumeId, filePath, newFilePath)
.then(function success() {
Notifications.success('File successfully renamed', newFilePath);
return VolumeBrowserService.ls(ctrl.volumeId, ctrl.state.path);
})
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to rename file');
});
};
VolumeBrowserService.rename(this.volumeId, filePath, newFilePath)
.then(function success() {
Notifications.success('File successfully renamed', newFilePath);
return VolumeBrowserService.ls(ctrl.volumeId, ctrl.state.path);
})
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to rename file');
});
};
this.delete = function(file) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
this.delete = function (file) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
ModalService.confirmDeletion(
'Are you sure that you want to delete ' + filePath + ' ?',
function onConfirm(confirmed) {
if(!confirmed) { return; }
ModalService.confirmDeletion('Are you sure that you want to delete ' + filePath + ' ?', function onConfirm(confirmed) {
if (!confirmed) {
return;
}
deleteFile(filePath);
}
);
};
this.download = function(file) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
VolumeBrowserService.get(this.volumeId, filePath)
.then(function success(data) {
var downloadData = new Blob([data.file]);
FileSaver.saveAs(downloadData, file);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to download file');
});
};
this.up = function() {
var parentFolder = parentPath(this.state.path);
browse(parentFolder);
};
this.browse = function(folder) {
var path = buildPath(this.state.path, folder);
browse(path);
};
function deleteFile(file) {
VolumeBrowserService.delete(ctrl.volumeId, file)
.then(function success() {
Notifications.success('File successfully deleted', file);
return VolumeBrowserService.ls(ctrl.volumeId, ctrl.state.path);
})
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to delete file');
});
}
function browse(path) {
VolumeBrowserService.ls(ctrl.volumeId, path)
.then(function success(data) {
ctrl.state.path = path;
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to browse volume');
});
}
this.onFileSelectedForUpload = function onFileSelectedForUpload(file) {
VolumeBrowserService.upload(ctrl.state.path, file, ctrl.volumeId)
.then(function onFileUpload() {
onFileUploaded();
})
.catch(function onFileUpload(err) {
Notifications.error('Failure', err, 'Unable to upload file');
});
};
};
function parentPath(path) {
if (path.lastIndexOf('/') === 0) {
return '/';
this.download = function (file) {
var filePath = this.state.path === '/' ? file : this.state.path + '/' + file;
VolumeBrowserService.get(this.volumeId, filePath)
.then(function success(data) {
var downloadData = new Blob([data.file]);
FileSaver.saveAs(downloadData, file);
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to download file');
});
};
this.up = function () {
var parentFolder = parentPath(this.state.path);
browse(parentFolder);
};
this.browse = function (folder) {
var path = buildPath(this.state.path, folder);
browse(path);
};
function deleteFile(file) {
VolumeBrowserService.delete(ctrl.volumeId, file)
.then(function success() {
Notifications.success('File successfully deleted', file);
return VolumeBrowserService.ls(ctrl.volumeId, ctrl.state.path);
})
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to delete file');
});
}
var split = _.split(path, '/');
return _.join(_.slice(split, 0, split.length - 1), '/');
}
function buildPath(parent, file) {
if (parent === '/') {
return parent + file;
function browse(path) {
VolumeBrowserService.ls(ctrl.volumeId, path)
.then(function success(data) {
ctrl.state.path = path;
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to browse volume');
});
}
return parent + '/' + file;
}
this.onFileSelectedForUpload = function onFileSelectedForUpload(file) {
VolumeBrowserService.upload(ctrl.state.path, file, ctrl.volumeId)
.then(function onFileUpload() {
onFileUploaded();
})
.catch(function onFileUpload(err) {
Notifications.error('Failure', err, 'Unable to upload file');
});
};
this.$onInit = function() {
HttpRequestHelper.setPortainerAgentTargetHeader(this.nodeName);
VolumeBrowserService.ls(this.volumeId, this.state.path)
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to browse volume');
});
};
function parentPath(path) {
if (path.lastIndexOf('/') === 0) {
return '/';
}
function onFileUploaded() {
refreshList();
}
var split = _.split(path, '/');
return _.join(_.slice(split, 0, split.length - 1), '/');
}
function refreshList() {
browse(ctrl.state.path);
}
function buildPath(parent, file) {
if (parent === '/') {
return parent + file;
}
return parent + '/' + file;
}
this.$onInit = function () {
HttpRequestHelper.setPortainerAgentTargetHeader(this.nodeName);
VolumeBrowserService.ls(this.volumeId, this.state.path)
.then(function success(data) {
ctrl.files = data;
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to browse volume');
});
};
}]);
function onFileUploaded() {
refreshList();
}
function refreshList() {
browse(ctrl.state.path);
}
},
]);