Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mccalluc/user files csv filtering #2041

Merged
merged 4 commits into from
Aug 24, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@
.controller('UserFileBrowserFilesCtrl', UserFileBrowserFilesCtrl);

UserFileBrowserFilesCtrl.$inject = [
'$httpParamSerializer',
'$log',
'$q',
'userFileBrowserFactory',
'userFileFiltersService',
'userFileParamsService',
'userFileSortsService',
'gridOptionsService'
];

function UserFileBrowserFilesCtrl (
$httpParamSerializer,
$log,
$q,
userFileBrowserFactory,
userFileFiltersService,
userFileParamsService,
userFileSortsService,
gridOptionsService
) {
Expand Down Expand Up @@ -62,6 +64,12 @@
};

gridOptionsService.appScopeProvider = vm;
vm.downloadFilterQuery = function () {
return $httpParamSerializer({
fq: userFileParamsService.fq(),
sort: userFileParamsService.sort()
});
};
vm.gridOptions = gridOptionsService;
vm.gridOptions.onRegisterApi = function (api) {
api.core.on.sortChanged(null, vm.sortChanged);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
<div
ui-grid="$ctrl.gridOptions"
ui-grid-resize-columns
class="grid">
</div>
<div class="col-lg-10 col-md-10 col-sm-9" id="main-area">
<div>
<a href="/files_download?{{ $ctrl.downloadFilterQuery() }}"><i class="fa fa-arrow-circle-o-down"></i> Download as CSV</a>
</div>
<div class="m-r-1">
<!-- Bootstrap col classes are using the window width, not our inner div.
#table-filter has a margin-left, so do something similar on the other side -->
<!-- TODO: Why isn't it full height? -->
<div
ui-grid="$ctrl.gridOptions"
ui-grid-resize-columns
class="grid">
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
(function () {
'use strict';
angular
.module('refineryApp')
.factory('userFileParamsService', userFileParamsService);

userFileParamsService.$inject = [
'userFileFiltersService',
'userFileSortsService'
];

function userFileParamsService (
userFileFiltersService,
userFileSortsService
) {
var characterSuffix = '_Characteristics_generic_s';
var factorSuffix = '_Factor_Value_generic_s';
var params = {
limit: 100, // Default is 100,000. Immutability make it hard in python.
fq: function () {
var filters = Object.keys(userFileFiltersService).map(function (key) {
var values = userFileFiltersService[key];
// TODO: escaping!
var orValues = values.map(function (value) {
return '(' +
key + characterSuffix + ':"' + value + '" OR ' +
key + factorSuffix + ':"' + value + '")';
}).join(' OR ');
return '(' + orValues + ')';
});
return filters.join(' AND ');
},
sort: function () {
return userFileSortsService.fields.map(function (field) {
var name = field.name;
var direction = field.direction;
return [
name + characterSuffix + ' ' + direction,
name + factorSuffix + ' ' + direction].join(', ');
}).join(', ');
}
};
return params;
}
})();
34 changes: 3 additions & 31 deletions refinery/ui/source/js/user-file-browser/services/user-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,49 +8,21 @@
userFileService.$inject = [
'$resource',
'settings',
'userFileFiltersService',
'userFileSortsService'
'userFileParamsService'
];

function userFileService (
$resource,
settings,
userFileFiltersService,
userFileSortsService
userFileParamsService
) {
var characterSuffix = '_Characteristics_generic_s';
var factorSuffix = '_Factor_Value_generic_s';
var userFile = $resource(
settings.appRoot + settings.refineryApiV2 + '/files/',
{},
{
query: {
method: 'GET',
params: {
limit: 100, // Default is 100,000. Immutability make it hard in python.
fq: function () {
var filters = Object.keys(userFileFiltersService).map(function (key) {
var values = userFileFiltersService[key];
// TODO: escaping!
var orValues = values.map(function (value) {
return '(' +
key + characterSuffix + ':"' + value + '" OR ' +
key + factorSuffix + ':"' + value + '")';
}).join(' OR ');
return '(' + orValues + ')';
});
return filters.join(' AND ');
},
sort: function () {
return userFileSortsService.fields.map(function (field) {
var name = field.name;
var direction = field.direction;
return [
name + characterSuffix + ' ' + direction,
name + factorSuffix + ' ' + direction].join(', ');
}).join(', ');
}
}
params: userFileParamsService
}
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,5 @@
</div>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-9" id="main-area">
<div><a href="/files_download"><i class="fa fa-arrow-circle-o-down"></i> Download as CSV</a></div>
<div class="m-r-1">
<!-- Bootstrap col classes are using the window width, not our inner div.
#table-filter has a margin-left, so do something similar on the other side -->
<!-- TODO: Why isn't it full height? -->
<rp-user-file-browser-files></rp-user-file-browser-files>
</div>
</div>
<rp-user-file-browser-files></rp-user-file-browser-files>
</div>