Skip to content
This repository has been archived by the owner on Jan 7, 2020. It is now read-only.

Commit

Permalink
Merge pull request #342 from btzc/em-177
Browse files Browse the repository at this point in the history
em-177 clicking pagination scrolls to the top
  • Loading branch information
Randy P authored Feb 19, 2018
2 parents b0c9186 + 2c562f9 commit 091ed09
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 48 deletions.
5 changes: 5 additions & 0 deletions modules/core/client/app/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ angular.module(ApplicationConfiguration.applicationModuleName).config(['$locatio

angular.module(ApplicationConfiguration.applicationModuleName).run(function ($rootScope, $state, $uibModalStack, Authentication, _, $cookies, Application, ContextService, AlertService) {

$rootScope.scrollTop = function() {
var top = document.getElementsByClassName('view-body-container');
top[0].scrollTo(0, 0);
}

// Check authentication before changing state
$rootScope.$on('$stateChangeStart', function (event, toState, toParams) {
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ angular.module ('comment')
restrict: 'E',
templateUrl : 'modules/project-comments/client/views/public-comments/list.html',
controllerAs: 's',
controller: function ($scope, $filter, NgTableParams, Authentication, CommentModel, UserModel, CommentPeriodModel, _) {
controller: function ($scope, $rootScope, $filter, NgTableParams, Authentication, CommentModel, UserModel, CommentPeriodModel, _) {
var s = this;
var project = s.project = $scope.project;
var period = s.period = $scope.period;
Expand Down Expand Up @@ -165,6 +165,9 @@ angular.module ('comment')

var pagination = tableState.pagination;
var sort = tableState.sort;
if(tableState) {
$rootScope.scrollTop();
}

var start = pagination.start || 0; // This is NOT the page number, but the index of item in the list that you want to use to display the table.
var limit = pagination.number || s.pageSize; // Number of entries showed per page.
Expand Down
105 changes: 59 additions & 46 deletions modules/vcs/client/controllers/vc.controller.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,52 @@
'use strict';

angular.module ('vcs')

// -------------------------------------------------------------------------
//
// controller for listing vcs
//
// -------------------------------------------------------------------------
.controller ('controllerVcList',
angular.module('vcs')

// -------------------------------------------------------------------------
//
// controller for scrolling to the top on button click
//
// -------------------------------------------------------------------------

.controller('scrollTopCtrl',
['$rootScope', 'ngTableEventsChannel',
function ($rootScope, ngTableEventsChannel) {
ngTableEventsChannel.onPagesChanged($rootScope.scrollTop, $rootScope);
}])

// -------------------------------------------------------------------------
//
// controller for listing vcs
//
// -------------------------------------------------------------------------

.controller('controllerVcList',
['$scope', '$rootScope', '$stateParams', 'VcModel', 'NgTableParams', 'PILLARS',
function ($scope, $rootScope, $stateParams, VcModel, NgTableParams, PILLARS) {
var self = this;

//
// map out any supporting data
//
self.pillars = PILLARS.map (function (e) {
return {id:e,title:e};
self.pillars = PILLARS.map(function (e) {
return { id: e, title: e };
});
self.project = $stateParams.project;

//
// set or reset the collection
//
var setData = function () {
VcModel.forProject ($stateParams.project).then (function (data) {
VcModel.forProject($stateParams.project).then(function (data) {
self.collection = data;
self.tableParams = new NgTableParams ({count: 10}, {dataset: data});
self.tableParams = new NgTableParams({ count: 10 }, { dataset: data });
});
};

//
// listen for when to reset
//
var unbind = $rootScope.$on('refreshVcList', function() {
var unbind = $rootScope.$on('refreshVcList', function () {
setData();
});
$scope.$on('$destroy', unbind);
Expand All @@ -44,26 +57,26 @@ angular.module ('vcs')
setData();
}])

.controller ('controllerAddTopicModal',
['NgTableParams','$uibModalInstance', '$scope', '_', '$stateParams', 'codeFromTitle', 'VcModel', 'TopicModel', 'PILLARS', 'ArtifactModel',
.controller('controllerAddTopicModal',
['NgTableParams', '$uibModalInstance', '$scope', '_', '$stateParams', 'codeFromTitle', 'VcModel', 'TopicModel', 'PILLARS', 'ArtifactModel',
function (NgTableParams, $uibModalInstance, $scope, _, $stateParams, codeFromTitle, VcModel, TopicModel, PILLARS, ArtifactModel) {

var self = this;
self.current = [];
self.currentObjs = [];
self.project = $stateParams.project;

self.pillars = PILLARS.map (function (e) {
return {id:e,title:e};
self.pillars = PILLARS.map(function (e) {
return { id: e, title: e };
});

self.showFilter = true;
self.okDisabled = true;
self.cancelDisabled = false;

// Show all VC types, either pathway or valued components
TopicModel.getSorted('name').then( function (data) {
self.tableParams = new NgTableParams ({},{dataset: data});
TopicModel.getSorted('name').then(function (data) {
self.tableParams = new NgTableParams({}, { dataset: data });
$scope.$apply();
});

Expand All @@ -74,8 +87,8 @@ angular.module ('vcs')
self.currentObjs.push(item);
self.current.push(item._id);
} else {
_.remove(self.currentObjs, {_id: item._id});
_.remove(self.current, function(n) {return n === item._id;});
_.remove(self.currentObjs, { _id: item._id });
_.remove(self.current, function (n) { return n === item._id; });
}

self.okDisabled = _.size(self.currentObjs) === 0;
Expand All @@ -92,35 +105,35 @@ angular.module ('vcs')
self.cancelDisabled = true;

var savedArray = [];
_.each( self.currentObjs, function(obj, idx) {
_.each(self.currentObjs, function (obj, idx) {
VcModel.getNew().then(function (m) {
m.project = $scope.project;
m.name = obj.name;
m.title = obj.name;
m.pillar = obj.pillar;
m.type = obj.type;
VcModel.query({project: $scope.project})
.then(function(/* data */) {
VcModel.query({ project: $scope.project })
.then(function (/* data */) {
VcModel.saveCopy(m)
.then(function (saved) {
return ArtifactModel.getNew()
.then( function (f) {
.then(function (f) {
f.valuedComponents.push(m);
f.name = obj.name;
f.typeCode = 'valued-component';
f.project = $scope.project._id;
return ArtifactModel.saveCopy(f);
})
.then( function (art) {
.then(function (art) {
// Save the reference that this VC relates to. We will look to
// re-use this to build up the package of VC's later.
saved.artifact = art;
return VcModel.save(saved);
});
})
.then( function (obj) {
.then(function (obj) {
savedArray.push(obj);
if (idx === self.currentObjs.length-1) {
if (idx === self.currentObjs.length - 1) {
// Return the collection back to the caller
$uibModalInstance.close(savedArray);
// since we are closing, this doesn't matter...
Expand All @@ -129,7 +142,7 @@ angular.module ('vcs')
}
});
},
function(/* error */) {
function (/* error */) {
// an error occurred...
self.okDisabled = _.size(self.currentObjs) === 0;
self.cancelDisabled = false;
Expand All @@ -143,12 +156,12 @@ angular.module ('vcs')
};
}])

// -------------------------------------------------------------------------
//
// controller for editing or adding vcs
//
// -------------------------------------------------------------------------
.controller ('controllerEditVcModal',
// -------------------------------------------------------------------------
//
// controller for editing or adding vcs
//
// -------------------------------------------------------------------------
.controller('controllerEditVcModal',
['$uibModalInstance', '$scope', '_', 'codeFromTitle', 'VcModel', 'TopicModel', 'PILLARS',
function ($uibModalInstance, $scope, _, codeFromTitle, VcModel, TopicModel, PILLARS) {
var self = this;
Expand All @@ -170,25 +183,25 @@ angular.module ('vcs')
// -------------------------------------------------------------------------
this.selectTopic = function () {
var self = this;
TopicModel.getTopicsForPillar (this.vc.pillar).then (function (topics) {
TopicModel.getTopicsForPillar(this.vc.pillar).then(function (topics) {
self.topics = topics;
$scope.$apply();
});
};
this.ok = function () {
if (this.mode === 'add') {
VcModel.saveModel ().then (function (result) {
VcModel.saveModel().then(function (result) {
$uibModalInstance.close(result);
});
}
else if (this.mode === 'edit') {
VcModel.saveModel ().then (function (result) {
$scope.vc = _.cloneDeep (result);
VcModel.saveModel().then(function (result) {
$scope.vc = _.cloneDeep(result);
$uibModalInstance.close(result);
});
}
else {
$uibModalInstance.dismiss ('cancel');
$uibModalInstance.dismiss('cancel');
}
};
this.cancel = function () {
Expand All @@ -201,19 +214,19 @@ angular.module ('vcs')
//
if (this.mode === 'add') {
this.dmode = 'Add';
VcModel.getNew ().then (function (model) {
VcModel.getNew().then(function (model) {
self.vc = model;
self.selectTopic ();
self.selectTopic();
});
} else if (this.mode === 'edit') {
this.dmode = 'Edit';
this.vc = VcModel.getCopy ($scope.vc);
VcModel.setModel (this.vc);
this.selectTopic ();
this.vc = VcModel.getCopy($scope.vc);
VcModel.setModel(this.vc);
this.selectTopic();
} else {
this.dmode = 'View';
this.vc = $scope.vc;
this.selectTopic ();
this.selectTopic();
}
}]);

Expand Down
2 changes: 1 addition & 1 deletion modules/vcs/client/views/vc-list.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ <h1>Valued Components</h1>
</button>
</div>
<div class="table-container">
<table class="vc-list table table-hover" ng-table="tableParams" show-filter="true">
<table class="vc-list table table-hover" ng-table="tableParams" show-filter="true" ng-controller="scrollTopCtrl">
<tr ng-repeat="o in $data" ui-sref="p.vc.detail({vcId:o._id})">
<td data-title="'Name'"
filter="{'name':'text'}"
Expand Down

0 comments on commit 091ed09

Please sign in to comment.