From ff12b7f98ee2309189d50b99ec40a7296990d964 Mon Sep 17 00:00:00 2001 From: Jaden Diefenbaugh <blakcap@users.noreply.github.com> Date: Tue, 14 Mar 2017 13:40:55 +0100 Subject: [PATCH] now using checkbox delete for rm exps, fixed updated date on exp list --- .../app/controllers/groupsController.js | 46 +++-- .../static/reports/app/services/urlService.js | 4 +- .../reports/panels/experiment_table.html | 186 ++++++++++-------- .../templates/reports/panels/viewer.html | 2 +- .../web/reports/templates/reports/report.html | 4 +- beat/web/reports/templatetags/report_tags.py | 6 +- 6 files changed, 143 insertions(+), 105 deletions(-) diff --git a/beat/web/reports/static/reports/app/controllers/groupsController.js b/beat/web/reports/static/reports/app/controllers/groupsController.js index 39c08e47b..7a0c4bdd0 100644 --- a/beat/web/reports/static/reports/app/controllers/groupsController.js +++ b/beat/web/reports/static/reports/app/controllers/groupsController.js @@ -19,24 +19,42 @@ * You should have received a copy of the GNU Affero Public License along * with the BEAT platform. If not, see http://www.gnu.org/licenses/. */ -// this controller handles the 'groups' partial, where groups of experiments are managed -angular.module('reportApp').controller('GroupsController', ['$scope', 'GroupsService', function ($scope, GroupsService){ - let vm = this; - - vm.report = $scope.report; - // GroupsService stuff to be used directly in ui - vm.groups = GroupsService.groups; +/* + * GroupsController + * provides access to the groups data to Django templates, + * mostly used for handling the removal of experiments from the report + */ +angular.module('reportApp').controller('GroupsController', ['$scope', '$http', 'GroupsService', 'UrlService', function ($scope, $http, GroupsService, UrlService){ + let vm = this; - vm.createGroup = function(name) { - GroupsService.createGroup(name); - vm.newGroupName = ''; + vm.expNamesToRemove = []; + vm.toggleExpName = (expName) => { + console.log(vm.expNamesToRemove); + let idx = vm.expNamesToRemove.indexOf(expName); + if(idx > -1){ + vm.expNamesToRemove.splice(idx, 1); + } else { + vm.expNamesToRemove.push(expName); + } + console.log(vm.expNamesToRemove); }; - // createGroup input val - vm.newGroupName = ''; + vm.removeExperiments = () => { + if(vm.expNamesToRemove.length === 0){ + return; + } - vm.removeExperiment = (experiment_name) => { - beat.ui.report.remove_experiment('report_remove_experiment', experiment_name, $scope); + let url = UrlService.getRemoveExperimentUrl(); + return $http({ + headers: {'Content-Type': 'application/json'}, + url, + method: "POST", + data: { + experiments: [...vm.expNamesToRemove] + } + }) + .then(res => location.reload()) + ; }; }]); diff --git a/beat/web/reports/static/reports/app/services/urlService.js b/beat/web/reports/static/reports/app/services/urlService.js index 09e50c576..57e1594cc 100644 --- a/beat/web/reports/static/reports/app/services/urlService.js +++ b/beat/web/reports/static/reports/app/services/urlService.js @@ -67,6 +67,7 @@ angular.module('reportApp').factory('UrlService', [function(){ const getApiUrl = (apiSubpath) => `${apiPath()}${apiSubpath}`; const getCompileRstUrl = () => `${getApiUrl(`${reportByName}rst/`)}`; + const getRemoveExperimentUrl = () => `${getApiUrl(`${reportByName}remove/`)}`; extractUsingCurrentUrl(); @@ -74,6 +75,7 @@ angular.module('reportApp').factory('UrlService', [function(){ getExperimentUrl, getBlockUrl, getDatabaseUrl, - getCompileRstUrl + getCompileRstUrl, + getRemoveExperimentUrl }; }]); diff --git a/beat/web/reports/templates/reports/panels/experiment_table.html b/beat/web/reports/templates/reports/panels/experiment_table.html index a728dd620..26e489d63 100644 --- a/beat/web/reports/templates/reports/panels/experiment_table.html +++ b/beat/web/reports/templates/reports/panels/experiment_table.html @@ -65,95 +65,111 @@ </div> </div><!-- row --> -<div class="row"> - <div class="col-sm-12"> - <div class="scrollable table-responsive"> - <table id="{{ panel_id }}" class="table table-hover table-condensed object-list experiment-list"> - <thead> - <tr> - <th class='delete'></th> - <th class="attestation"></th> - <th class="privacy"></th> - <th class="status"></th> - <th class="date">Updated</th> - <th>Name</th> - <th class="datasets">Databases/Protocols</th> - <th class="analyzers">Analyzers</th> - </tr> - </thead> - <tbody> - {% for obj in objects %} - {% with obj.get_status_display as status %} - <tr class="{{ status }}"> - {% if owner %} - <td class="delete" ng-controller='GroupsController as ctrl'> - <span class='btn-group action-buttons'> - <a - class='btn-delete' - title="Delete Experiment" - data-toggle="tooltip" - data-placement="top"> - <span ng-click="ctrl.removeExperiment('{{ obj.fullname }}')"> - <i class='fa fa-times fa-2x'></i> +<div ng-controller='GroupsController as ctrl'> + <div class="row" > + <div class="col-sm-12"> + <div class="scrollable table-responsive"> + <table id="{{ panel_id }}" class="table table-hover table-condensed object-list experiment-list"> + <thead> + <tr> + {% if not report_number %} + <th class='delete'></th> + {% endif %} + <th class="attestation"></th> + <th class="privacy"></th> + <th class="status"></th> + <th class="date">Updated</th> + <th>Name</th> + <th class="datasets">Databases/Protocols</th> + <th class="analyzers">Analyzers</th> + </tr> + </thead> + <tbody> + {% for obj in objects %} + {% with obj.get_status_display as status %} + <tr class="{{ status }}"> + {% if not report_number %} + <td class="delete"> + <input + name='ctrl.expNamesToRemove[]' + type="checkbox" + value="{{ obj.fullname }}" + ng-checked="ctrl.expNamesToRemove.indexOf('{{ obj.fullname }}') > -1" + ng-click="ctrl.toggleExpName('{{ obj.fullname }}')" + > + </td> + {% endif %} + <td class="attestation"> + {% if obj.attestation %} + <a class="icon-link" href="{% url 'attestations:view' obj.attestation.number %}" title="{% if obj.attestation.locked %}Locked{% else %}Attested{% endif %} (click to view)" data-toggle="tooltip" data-placement="top"> + {% if obj.attestation.locked %} + <span class="icon-locked fa-stack"> + <i class="fa fa-certificate fa-stack-2x"></i> + <i class="fa fa-lock fa-stack-1x fa-inverse"></i> </span> + {% else %} + <i class="icon-attested fa fa-certificate"></i> + {% endif %} </a> - </span> - </td> - {% endif %} - <td class="attestation"> - {% if obj.attestation %} - <a class="icon-link" href="{% url 'attestations:view' obj.attestation.number %}" title="{% if obj.attestation.locked %}Locked{% else %}Attested{% endif %} (click to view)" data-toggle="tooltip" data-placement="top"> - {% if obj.attestation.locked %} - <span class="icon-locked fa-stack"> - <i class="fa fa-certificate fa-stack-2x"></i> - <i class="fa fa-lock fa-stack-1x fa-inverse"></i> - </span> - {% else %} - <i class="icon-attested fa fa-certificate"></i> {% endif %} - </a> + </td> + <td class="privacy"> + <a title="{{ obj.get_sharing_display }}" data-toggle="tooltip" data-placement="top"> + {% if obj.get_sharing_display == 'Private' %} + <i class="fa fa-user fa-2x"></i> + {% elif obj.get_sharing_display == 'Shared' %} + <i class="fa fa-users fa-2x"></i> + {% else %} + <i class="fa fa-globe fa-2x"></i> + {% endif %} + </a> + </td> + <td class="status"> + <a title="{{ status }}" data-toggle="tooltip" data-placement="top"> + {% if status == 'Done' %} + <i class="icon-done fa fa-check fa-2x"></i> + {% elif status == 'Scheduled' %} + <i class="icon-scheduled fa fa-calendar-check-o fa-2x"></i> + {% elif status == 'Pending' %} + <i class="icon-pending fa fa-play fa-2x"></i> + {% elif status == 'Failed' %} + <i class="icon-failed fa fa-bug fa-2x"></i> + {% elif status == 'Canceling' %} + <i class="icon-canceling fa fa-power-off fa-2x"></i> + {% else %} + <i class="icon-running fa fa-refresh fa-spin fa-2x"></i> + {% endif %} + </a> + </td> + {% if obj.end_date %} + <td class="date">{{ obj.end_date|date }}</td> + {% elif obj.start_date %} + <td class="date">{{ obj.start_date|date }}</td> + {% else %} + <td class="date">{{ obj.creation_date|date }}</td> {% endif %} - </td> - <td class="privacy"> - <a title="{{ obj.get_sharing_display }}" data-toggle="tooltip" data-placement="top"> - {% if obj.get_sharing_display == 'Private' %} - <i class="fa fa-user fa-2x"></i> - {% elif obj.get_sharing_display == 'Shared' %} - <i class="fa fa-users fa-2x"></i> - {% else %} - <i class="fa fa-globe fa-2x"></i> - {% endif %} - </a> - </td> - <td class="status"> - <a title="{{ status }}" data-toggle="tooltip" data-placement="top"> - {% if status == 'Done' %} - <i class="icon-done fa fa-check fa-2x"></i> - {% elif status == 'Scheduled' %} - <i class="icon-scheduled fa fa-calendar-check-o fa-2x"></i> - {% elif status == 'Pending' %} - <i class="icon-pending fa fa-play fa-2x"></i> - {% elif status == 'Failed' %} - <i class="icon-failed fa fa-bug fa-2x"></i> - {% elif status == 'Canceling' %} - <i class="icon-canceling fa fa-power-off fa-2x"></i> - {% else %} - <i class="icon-running fa fa-refresh fa-spin fa-2x"></i> - {% endif %} - </a> - </td> - <td class="date">{{ obj.updated|date }}</td> - <td class="name"><a href="{{ obj.get_absolute_url }}" data-toggle="tooltip" data-placement="top" title="Click to view">{{ obj.fullname }}</a></td> - <td class="datasets">{{ obj.databases_and_protocols|join:"," }}</td> - <td class="analyzers">{{ obj.analyzers|join:"," }}</td> - </tr> - {% endwith %} - {% endfor %} - </tbody> - </table> - </div> - </div><!-- col --> -</div><!-- row --> + <td class="name"><a href="{{ obj.get_absolute_url }}" data-toggle="tooltip" data-placement="top" title="Click to view">{{ obj.fullname }}</a></td> + <td class="datasets">{{ obj.databases_and_protocols|join:"," }}</td> + <td class="analyzers">{{ obj.analyzers|join:"," }}</td> + </tr> + {% endwith %} + {% endfor %} + </tbody> + </table> + </div> + </div><!-- col --> + </div><!-- row --> + {% if not report_number %} + <div> + <button + ng-disabled='ctrl.expNamesToRemove.length == 0' + class='btn btn-danger' + ng-click="ctrl.removeExperiments()"> + Remove Selected Experiments + </button> + </div> + {% endif %} +</div> {% else %} <!-- if objects --> <div class="row"> <div class="col-sm-12 not-found"> diff --git a/beat/web/reports/templates/reports/panels/viewer.html b/beat/web/reports/templates/reports/panels/viewer.html index 6ced52c7f..c3a84b884 100644 --- a/beat/web/reports/templates/reports/panels/viewer.html +++ b/beat/web/reports/templates/reports/panels/viewer.html @@ -54,7 +54,7 @@ </div>{# panel-heading #} <div id="collapse-info" class="panel-collapse collapse in" role="tabpanel" aria-labelledby="info-heading"> <div class="panel-body"> - {% experiment_table exps owner "experiment-list-test" %} + {% experiment_table exps owner report_number "experiment-list-test" %} </div>{# panel-body #} </div>{# collapse #} </div>{# panel #} diff --git a/beat/web/reports/templates/reports/report.html b/beat/web/reports/templates/reports/report.html index 3a7c0950a..1ba856a11 100644 --- a/beat/web/reports/templates/reports/report.html +++ b/beat/web/reports/templates/reports/report.html @@ -110,7 +110,7 @@ <script src="{% fingerprint "reports/app/directives/theColumn.js" %}" type="text/javascript" charset="utf-8"></script> <!-- edit view --> - {% if report and user and not report_number %} + {% if not report_number %} <script src="{% fingerprint "reports/app/directives/edit/addGroupMenu.js" %}" type="text/javascript" charset="utf-8"></script> <script src="{% fingerprint "reports/app/directives/edit/addItemsMenu.js" %}" type="text/javascript" charset="utf-8"></script> <script src="{% fingerprint "reports/app/directives/edit/itemContainer.js" %}" type="text/javascript" charset="utf-8"></script> @@ -201,7 +201,7 @@ {% endwith %} -{% report_viewer report owner %} +{% report_viewer report owner report_number %} {% endif %} diff --git a/beat/web/reports/templatetags/report_tags.py b/beat/web/reports/templatetags/report_tags.py index 29b93c20f..a42ada0b8 100644 --- a/beat/web/reports/templatetags/report_tags.py +++ b/beat/web/reports/templatetags/report_tags.py @@ -105,7 +105,7 @@ def report_actions(context, object, display_count): @register.inclusion_tag('reports/panels/viewer.html', takes_context=True) -def report_viewer(context, object, owner): +def report_viewer(context, object, owner, report_number): '''Composes the search results for visualization Parameters: @@ -126,6 +126,7 @@ def report_viewer(context, object, owner): object=object, owner=owner, exps=object.experiments.all(), + report_number=report_number, URL_PREFIX=context['URL_PREFIX'], ) @@ -253,10 +254,11 @@ register.inclusion_tag('reports/dialogs/report_saved.html')(report_saved) @register.inclusion_tag('reports/panels/experiment_table.html', takes_context=True) -def experiment_table(context, objects, owner, id): +def experiment_table(context, objects, owner, report_number, id): return dict( request=context['request'], objects=objects, owner=owner, panel_id=id, + report_number=report_number ) -- GitLab