-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from virginiacommonwealthuniversity/release/1.7.0
Release 1.7.0 - Ordinal Indicators Enhancement
- Loading branch information
Showing
4 changed files
with
164 additions
and
121 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "t4-utils-2", | ||
"version": "1.6.1", | ||
"version": "1.7.0", | ||
"description": "A Javascript Library of Utility Classes and Extensions for TerminalFour Programmable Layouts", | ||
"main": "dist/8.4/T4Utils.min.js", | ||
"author": "Joel Eisner <[email protected]>", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,110 +3,131 @@ | |
* @namespace ordinalIndicators | ||
* @extends T4Utils | ||
* @author Joel Eisner <[email protected]> | ||
* @version 1.2.0 | ||
* @version 2.0.0 | ||
* @example | ||
* T4Utils.ordinalIndicators | ||
*/ | ||
T4Utils.ordinalIndicators = T4Utils.ordinalIndicators || {}; | ||
|
||
/** | ||
* Find the index of the content as well as the position of the content within context to the page if it is the first/last of its kind | ||
* @function ordinalIndicators.pageInfo | ||
* @returns {Object} an object containing boolean values for first/last as well as an integer value for index | ||
* Find information about the content within context to the page and group | ||
* @function ordinalIndicators.info | ||
* @returns {Object} an object containing information such as index, count, first, last, etc. within context to the page and group | ||
* @example | ||
* T4Utils.ordinalIndicators.pageInfo; | ||
* T4Utils.ordinalIndicators.info; | ||
*/ | ||
T4Utils.ordinalIndicators.pageInfo = (function() { | ||
// Define the returned variables | ||
var pageCount, pageFirst, pageIndex, pageLast; | ||
// Create function to delete excess array objects if they have identical keys... | ||
function unique(array) { | ||
var comparer = function(a, b) { | ||
return a.key === b.key ? 0 : a.key < b.key ? -1 : 1; | ||
}; | ||
array.sort(comparer); | ||
for (var i = 0; i < array.length - 1; ++i) { | ||
if (comparer(array[i], array[i+1]) === 0) array.splice(i, 1); | ||
} | ||
return array; | ||
} | ||
T4Utils.ordinalIndicators.info = (function() { | ||
// If content is defined... | ||
if (T4Utils.contextIsContent) { | ||
// Grab all pieces of content on the page | ||
var cL = com.terminalfour.sitemanager.cache.utils.CSHelper.extractCachedContent( /* Extract all cached content from the page where... */ | ||
com.terminalfour.sitemanager.cache.utils.CSHelper.removeSpecialContent( /* ... deleted content is ignored... */ | ||
section.getContent( /* ... */ | ||
publishCache.getChannel(), 'en', com.terminalfour.sitemanager.cache.CachedContent.CURRENT, true /* ... and all other content is returned in the order as shown in SM */ | ||
) | ||
) | ||
); | ||
// Define an array of key/pieces objects based on each unique content-type ID on the page | ||
var listContentTypeIDs = []; | ||
for (var j = 0; j < cL.length; j++) { | ||
var contentPiece = cL[j], | ||
pieceID = contentPiece.getTemplateID(); | ||
listContentTypeIDs.push({ | ||
key: pieceID, | ||
pieces: [] | ||
}); | ||
var contentTypeID = content.getContentTypeID(), | ||
sectionID = section.getID(), | ||
contentID = content.getID(), | ||
oCH = new ContentHierarchy(), | ||
oCM = com.terminalfour.spring.ApplicationContextProvider.getBean(com.terminalfour.content.IContentManager), | ||
pageContents = oCH.getContent(dbStatement, sectionID, 'en'), | ||
sameContents = [], | ||
calcContents = [], | ||
pageCount = 0, | ||
offset = 0, | ||
groupID = 0, | ||
i, j, output; | ||
// Grab/store all content types of a kind | ||
for (i = 0; i < pageContents.length; i++) { | ||
var pageContent = oCM.get(pageContents[i], 'en'); | ||
// If the page content's content-type ID matches the current content-type ID, push its ID/page-index to the sameContents array | ||
if (pageContent.getContentTypeID() === contentTypeID) sameContents.push({ id: pageContent.getID(), pageIndex: i }); | ||
} | ||
unique(listContentTypeIDs); | ||
// Run through each piece of content, and put them in their corresponding key object pieces array | ||
for (var k = 0; k < cL.length; k++) { | ||
var cP = cL[k], | ||
ctID = cP.getTemplateID(), | ||
uID = cP.getID(); | ||
for (var l = 0; l < listContentTypeIDs.length; l++) { | ||
var contentTypeID = listContentTypeIDs[l]; | ||
if (ctID === contentTypeID.key) contentTypeID.pieces.push(uID); | ||
} | ||
} | ||
// Get the current content's content-type and unique ID's | ||
var this_ctID = content.getContentTypeID(), | ||
this_uID = content.getID(); | ||
// For each key/pieces object... | ||
for (var m = 0; m < listContentTypeIDs.length; m++) { | ||
// ... create a reference, ... | ||
var typeID = listContentTypeIDs[m]; | ||
// ... if the referenced object's key is equal to the current content's content-type ID... | ||
if (typeID.key === this_ctID) { | ||
// Define (of this content-type, in the scope of the entire page)... | ||
var pieces = typeID.pieces, /* All content */ | ||
pFirst = pieces[0], /* The first piece of content */ | ||
pLength = pieces.length, /* The amount of pieces of content */ | ||
pLast = pieces[pLength - 1]; /* The last piece of content */ | ||
// ... then assign values for pageCount, pageFirst, pageLast, and pageIndex based on the previously defined variables | ||
pageCount = pLength; | ||
pageFirst = pFirst === this_uID ? true : false; | ||
pageLast = pLast === this_uID ? true : false; | ||
for (var n = 0; n < pLength; n++) { | ||
var piece = pieces[n]; | ||
if (this_uID === piece) { | ||
pageIndex = n; | ||
break; /* Break */ | ||
} | ||
// Set the initial state of the index offset... | ||
offset = sameContents[0].pageIndex; | ||
// ... and store the amount of content there is of this kind | ||
pageCount += sameContents.length; | ||
// Calculate/store page/group information of a kind | ||
for (j = 0; j < pageCount; j++) { | ||
var piece = sameContents[j], | ||
pageIndex = piece.pageIndex, | ||
pageFirst = j === 0, | ||
pageLast = j === pageCount - 1, | ||
groupFirst = false, | ||
groupLast = false; | ||
// If this kind is not the first of its kind on the page... | ||
if (!pageFirst) { | ||
// Grab the previous kind | ||
var previousPiece = sameContents[j - 1]; | ||
// If this kind's page index minus the previous kind's page index is greater than 1... | ||
if (pageIndex - previousPiece.pageIndex > 1) { | ||
// ... adjust the offset,... | ||
offset = pageIndex; | ||
// ... this kind is the first of its group,... | ||
groupFirst = true; | ||
// ... and increment up the group ID | ||
groupID++; | ||
} | ||
break; /* Break */ | ||
} | ||
// If this kind is not the last of its kind on the page... | ||
if (!pageLast) { | ||
// Grab the next kind | ||
var nextPiece = sameContents[j + 1]; | ||
// If the next kind's page index minus this kind's page index is greater than 1, this kind is the last of its group | ||
if (nextPiece.pageIndex - pageIndex > 1) groupLast = true; | ||
} | ||
// Push the calculated content information as an object to the calcContents array | ||
calcContents.push({ | ||
id: piece.id, | ||
page: { | ||
count: pageCount, | ||
first: pageFirst, | ||
index: pageIndex, | ||
last: pageLast | ||
}, | ||
group: { | ||
first: pageFirst || groupFirst, | ||
id: groupID, | ||
index: pageIndex - offset, | ||
last: pageLast || groupLast | ||
} | ||
}); | ||
} | ||
// Return an object that contains... | ||
return { | ||
count: pageCount, /* (Integer) The amount of content of its kind on the page */ | ||
first: pageFirst, /* (Boolean) First of its kind on the page? */ | ||
index: pageIndex, /* (Integer) Position index of its kind on the page */ | ||
last: pageLast /* (Boolean) Last of its kind on the page? */ | ||
}; | ||
// Grab the current content's info and format it for return | ||
output = calcContents.filter(function (piece) { | ||
return piece.id === contentID; | ||
})[0]; | ||
output.group.count = calcContents.filter(function (piece) { | ||
return piece.group.id === output.group.id; | ||
}).length; | ||
output.group.amount = calcContents[calcContents.length - 1].group.id + 1; | ||
delete output['id']; | ||
// Return the output | ||
return output; | ||
} else { | ||
// ... otherwise, return an object that contains null key/value pairs | ||
return { | ||
count: null, | ||
first: null, | ||
index: null, | ||
last: null | ||
page: { | ||
count: null, | ||
first: null, | ||
index: null, | ||
last: null | ||
}, | ||
group: { | ||
amount: null, | ||
count: null, | ||
first: null, | ||
id: null, | ||
index: null, | ||
last: null | ||
} | ||
}; | ||
} | ||
})(); | ||
|
||
/** | ||
* Find information about the content within context to the page | ||
* @function ordinalIndicators.pageInfo | ||
* @returns {Object} an object containing information such as index, count, first, last, etc. within context to the page | ||
* @example | ||
* T4Utils.ordinalIndicators.pageInfo; | ||
*/ | ||
T4Utils.ordinalIndicators.pageInfo = T4Utils.ordinalIndicators.info.page; | ||
|
||
/** | ||
* Find how many pieces of content of the same kind are on the page | ||
* @member ordinalIndicators.pageCount | ||
|
@@ -128,7 +149,7 @@ T4Utils.ordinalIndicators.pageFirst = T4Utils.ordinalIndicators.pageInfo.first; | |
/** | ||
* Find the index of the content within context to the page | ||
* @member ordinalIndicators.pageIndex | ||
* @returns {Number} a integer representing the contents positon on the page (starts from 0) | ||
* @returns {Number} an integer representing the content's positon on the page (starts from 0) | ||
* @example | ||
* T4Utils.ordinalIndicators.pageIndex; | ||
*/ | ||
|
@@ -144,40 +165,31 @@ T4Utils.ordinalIndicators.pageIndex = T4Utils.ordinalIndicators.pageInfo.index; | |
T4Utils.ordinalIndicators.pageLast = T4Utils.ordinalIndicators.pageInfo.last; | ||
|
||
/** | ||
* Find if the position of the content within context to a group of the same content-type is the first/last of its kind | ||
* Find information about the content within context to the group | ||
* @function ordinalIndicators.groupInfo | ||
* @returns {Object} an object containing boolean values for first/last | ||
* @returns {Object} an object containing information such as index, count, first, last, etc. within context to the group | ||
* @example | ||
* T4Utils.ordinalIndicators.groupInfo; | ||
*/ | ||
T4Utils.ordinalIndicators.groupInfo = (function() { | ||
// If content is defined... | ||
if (T4Utils.contextIsContent) { | ||
var ctid = content.getContentTypeID(), | ||
sid = section.getID(), | ||
oCH = new ContentHierarchy(), | ||
oCM = com.terminalfour.spring.ApplicationContextProvider.getBean(com.terminalfour.content.IContentManager), | ||
contentInSection = oCH.getContent(dbStatement, sid, 'en'), | ||
groupFirst, groupLast; | ||
for (var i = 0; i < contentInSection.length; i++) { | ||
if (content.getID() === oCM.get(contentInSection[i], 'en').getID()) { | ||
groupFirst = i === 0 ? true : ctid !== oCM.get(contentInSection[i - 1], 'en').getContentTypeID() ? true : false; | ||
groupLast = i === contentInSection.length - 1 ? true : ctid !== oCM.get(contentInSection[i + 1], 'en').getContentTypeID() ? true : false; | ||
} | ||
} | ||
// Return an object that contains... | ||
return { | ||
first: groupFirst, /* (Boolean) First of its kind in a group? */ | ||
last: groupLast /* (Boolean) Last of its kind in a group? */ | ||
}; | ||
} else { | ||
// ... otherwise, return an object that contains null key/value pairs | ||
return { | ||
first: null, | ||
last: null | ||
}; | ||
} | ||
})(); | ||
T4Utils.ordinalIndicators.groupInfo = T4Utils.ordinalIndicators.info.group; | ||
|
||
/** | ||
* Find how many groups of the content's kind are on the page | ||
* @function ordinalIndicators.groupAmount | ||
* @returns {Number} an integer representing how many groups of the content's kind are on the page | ||
* @example | ||
* T4Utils.ordinalIndicators.groupAmount; | ||
*/ | ||
T4Utils.ordinalIndicators.groupAmount = T4Utils.ordinalIndicators.groupInfo.amount; | ||
|
||
/** | ||
* Find how many pieces of content are within the content's group | ||
* @function ordinalIndicators.groupCount | ||
* @returns {Number} an integer representing how many pieces of content are withing the content's group | ||
* @example | ||
* T4Utils.ordinalIndicators.groupCount; | ||
*/ | ||
T4Utils.ordinalIndicators.groupCount = T4Utils.ordinalIndicators.groupInfo.count; | ||
|
||
/** | ||
* Find if the position of the content within context to a group of the same content-type is the first of its kind | ||
|
@@ -188,6 +200,24 @@ T4Utils.ordinalIndicators.groupInfo = (function() { | |
*/ | ||
T4Utils.ordinalIndicators.groupFirst = T4Utils.ordinalIndicators.groupInfo.first; | ||
|
||
/** | ||
* Find the id of the content's group | ||
* @function ordinalIndicators.groupID | ||
* @returns {Number} an integer representing the id of the content's group | ||
* @example | ||
* T4Utils.ordinalIndicators.groupID; | ||
*/ | ||
T4Utils.ordinalIndicators.groupID = T4Utils.ordinalIndicators.groupInfo.id; | ||
|
||
/** | ||
* Find the index of the content within context of its group | ||
* @function ordinalIndicators.groupIndex | ||
* @returns {Number} an integer representing the content's positon in the group (starts from 0) | ||
* @example | ||
* T4Utils.ordinalIndicators.groupIndex; | ||
*/ | ||
T4Utils.ordinalIndicators.groupIndex = T4Utils.ordinalIndicators.groupInfo.index; | ||
|
||
/** | ||
* Find if the position of the content within context to a group of the same content-type is the last of its kind | ||
* @function ordinalIndicators.groupLast | ||
|