(function () {
'use strict';
// Side By Side List
angular
.module('mohistory')
.component('sbsList', {
templateUrl: 'app/components/side-by-side-list/side-by-side-list.component.html',
controller: sbsListCtrl,
controllerAs: 'sbsList',
bindings: {
'data': '<',
}
});
sbsListCtrl.$inject = [];
/**
* This component can render any of these mhs:displayClasses related-events,
* side-by-side-textborder-numbers, popular-posts, or side-by-side-list-callout
* @memberof mohistory
* @name sbsList
* @ngdoc component
*/
function sbsListCtrl() {
var vm = this;
/* ----- Variables ----- */
vm.blocks = {
'related-events': {
isInteractive: false,
usesParallax: true,
parallaxSpeed: 1,
},
'side-by-side-textborder-numbers': {
isInteractive: false,
usesParallax: true,
parallaxSpeed: -2,
},
// This block has two parallaxSpeeds
'side-by-side-list-callout': {
isInteractive: false,
usesParallax: true,
parallaxSpeed: [2, -2],
},
'popular-posts': {
isInteractive: false,
usesParallax: true,
parallaxSpeed: 1,
},
'announcements': {
isInteractive: false,
usesParallax: true,
parallaxSpeed: 2,
paged: true,
}
};
vm.locationLookup = {
'MHS': 'Missouri Historical Society',
'MHM': 'Missouri History Museum',
'SM': 'Soldiers Memorial',
'LRC': 'Library and Research Center',
'Off-Site': 'Off-Site',
'TBA': 'TBA',
};
vm.curBlockConfig = {};
vm.firstColLen = 0;
vm.secondColLen = 0;
vm.secondColStart = 0;
vm.curPage = 1;
vm.totalPages = 0;
vm.itemsPerPage = 6;
/* ----- Function Bindings ----- */
vm.$onInit = onInit;
vm.nextPage = nextPage;
vm.prevPage = prevPage;
vm.setPage = setPage;
/* ----- Function Definitions ----- */
/**
* Initiated when component is created. Runs code necessary for block
* configuration.
* @function onInit
* @memberof sbsList
*/
function onInit() {
console.log('Side by Side List')
vm.curBlockConfig = vm.blocks[vm.data['mhs:displayClass']];
vm.totalPages = Math.ceil(vm.data['mhs:parts'].length / vm.itemsPerPage);
vm.curPage = 1;
// Data for related-events and announcements needs to be split in half
// in order to be displayed in two separate columns
vm.firstColLen = Math.ceil(vm.itemsPerPage / 2);
vm.secondColLen = Math.floor(vm.itemsPerPage / 2);
vm.firstColStart = 0;
vm.secondColStart = vm.firstColStart + vm.firstColLen;
}
function nextPage() {
// Don't have to subtract by one because we haven't incremented yet.
vm.firstColStart = vm.curPage * vm.itemsPerPage;
vm.secondColStart = vm.firstColStart + vm.firstColLen;
vm.curPage += 1;
console.log('curPage: ', vm.curPage)
console.log('firstColStart: ', vm.firstColStart)
console.log('secondColStart: ', vm.secondColStart)
}
function prevPage() {
// Minus 1 for going backward and minus 1 for zero index
vm.firstColStart = (vm.curPage - 2) * vm.itemsPerPage;
vm.secondColStart = vm.firstColStart + vm.firstColLen;
vm.curPage -= 1;
console.log('curPage: ', vm.curPage)
console.log('firstColStart: ', vm.firstColStart)
console.log('secondColStart: ', vm.secondColStart)
}
function setPage(page) {
// Minus 1 for zero index conversion
vm.firstColStart = (page - 1) * vm.itemsPerPage;
vm.secondColStart = vm.firstColStart + vm.firstColLen;
vm.curPage = page;
console.log('curPage: ', vm.curPage)
console.log('firstColStart: ', vm.firstColStart)
console.log('secondColStart: ', vm.secondColStart)
}
};
})();