Alright! As promised, how to use what you need to get data from a specific filestore.
I've utilised/hacked some of Jared's code (Sorry Jared!) to make a quicker turnaround.
- the /opt/mango/overrides/modules/mangoUI/web/dev/controllers/userFileStore.js component
/*
File:userFileStore.js
Date:16/5/2019
Author: Matt 'Fox' Fox
Desc: quick file list generator of anchor links in angular js for @psysak
*/
define(['angular', 'require'], function(angular, require) {
function UserFilesController($http,maFileStore)
{
var ctrl = this;
ctrl.fileStoreName = 'default';
const fileStoreUrl = '/rest/v2/file-stores';
const fileStoreUrlSplit = fileStoreUrl.split('/');
this.$onChanges = function(e)
{
if(e.fileStoreName && e.fileStoreName.currentValue!==undefined)
{
ctrl.fileStoreName = e.fileStoreName.currentValue.split('/');
getFileList();
}
}
var toUrl = function(isDirectory) {
const parts = ctrl.fileStoreName.map(function(part) {
return encodeURIComponent(part);
});
let url = fileStoreUrl + '/' + parts.join('/');
if (isDirectory) {
url += '/';
}
return url;
};
var getFileList = function(){
if (ctrl.fileStoreName.length < 1) {
throw new Error('Must specify the file store name');
}
const folderUrl = toUrl(true);
return $http({
method: 'GET',
url: folderUrl
}).then(function(response) {
ctrl.fileStoreList=response.data.map(function(file) {
// return new FileStoreFile(ctrl.fileStoreName[0], file);
return new maFileStore.newFileStoreFile(ctrl.fileStoreName[0], file);
});
});
};
}
UserFilesController.$inject = ['$http','maFileStore'];
return {
bindings: {
fileStoreName:'<'
},
scope: {},
templateUrl: "/modules/mangoUI/web/dev/views/userFileStore.html",
// you can inject services into the controller
controller:('UserFilesController',UserFilesController)
};
});//define
- /opt/mango/overrides/modules/mangoUI/web/dev/views/userFileStore.html
<a ng-repeat="file in $ctrl.fileStoreList" class="md-icon-button md-button md-mangoLight-theme md-ink-ripple" style="display:inline-block;min-width:300px;" ng-if="!file.directory" download="" ng-href="file.url" ng-click="$ctrl.cancelClick($event)" aria-label="" href="{{file.url}}">
{{file.filename}}
<md-icon class="md-mangoLight-theme material-icons" style="display:inline-block" role="img" aria-label="file_download">file_download</md-icon>
<div class="md-ripple-container"></div></a>
- /opt/mango/overrides/modules/mangoUI/web/dev/userModule.js
define(['angular', 'require','./controllers/userFileStore.js'], function(angular, require,userFileStore)
{
var userModule = angular.module('userModule', ['maUiApp']);
try {
userModule.component('userFileStore', userFileStore);
}catch(e){console.log(e);}
});//define
EDIT:
Oops, forgot the component tag:
<user-file-store file-store-name="'default'"></user-file-store>
Let me know if you need further help.
Fox