App-Dochazka-WWW
view release on metacpan or search on metacpan
share/js/dochazka-www/viewer.js view on Meta::CPAN
//
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// 1. Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of SUSE LLC nor the names of its contributors may be
// used to endorse or promote products derived from this software without
// specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
// *************************************************************************
//
// app/viewer.js
//
// =========================
// Multi-day interval viewer
// =========================
//
// Given a multi-day interval object, trigger AJAX call "GET holiday/:tsrange"
// where tsrange is [ "beginDate 00:00", "endDate 23:59" ) - which will include
// all dates in the interval range and allow us to determine which ones are
// weekends/holidays and which are not.
//
// In the success function of that AJAX call, populate the haw ("holidays and
// weekends") object from the AJAX payload. A function "holidayOrWeekend()"
// takes each date string, canonicalizes it, and
// looks it up in the "haw" lookup object, and return true or false as
// appropriate.
//
// Next, the intervals-to-be-viewed array will be processed. First, to each
// date in haw, add an "intervals" array that will be empty at first. Second,
// iterate over all the intervals-to-be-viewed and push them into the respective
// "intervals" array in haw. At the same time, convert the time range string
// (e.g. "08:00-08:10") into a startTime-duration object (e.g. { "startTime":
// "08:00", "duration": "10" } where "duration" is always in minutes.
//
// Now, haw contains all information needed to construct the SVG blocks.
//
// Iterate over haw, writing SVG blocks. When a non-holiday/weekend date is
// detected immediately following a holiday/weekend date (that means Monday),
// insert a scale SVG block unless it is the first or last date in haw.
//
// At the end, draw a legend linking the colors to activity codes and write
// the total number of hours associated with each activity code.
//
//
"use strict";
define ([
"jquery",
"app/caches",
"app/svg-lib",
"ajax",
"current-user",
"datetime",
], function (
$,
appCaches,
svgLib,
ajax,
currentUser,
dt,
)
{
var haw,
sortedDates,
entryPoint = function (obj) {
// generate viewer HTML
var cu = currentUser('obj'),
date,
i,
r = '',
lwhow = false; // "Last [date] Was a Holiday Or Weekend"
console.log("currentUserObject", cu);
if (cu.fullname) {
r += '<b>' + cu.fullname + '</b>';
} else {
r += '<b>' + cu.nick + '</b>';
}
r += '<br><br>';
r += "Intervals (scheduled and clocked) during period from " + obj.beginDate + " to " + obj.endDate;
r += '<br><br>';
r += svgLib.dayViewerScale();
for (i = 0; i < sortedDates.length; i += 1) {
// draw new scale if needed (for each week, more or less)
date = sortedDates[i];
if (lwhow && ! holidayOrWeekend(date) && i !== sortedDates.length - 1) {
r += svgLib.dayViewerScale();
}
lwhow = holidayOrWeekend(date);
r += svgLib.dayViewerIntervals(date, haw[date], lwhow);
}
r += svgLib.dayViewerScale();
return r;
},
addScheduledIntervals = function (obj) {
var cu = currentUser('obj'),
i,
tsr = '[ ' + obj.beginDate + ' 00:00, ' + obj.endDate + ' 24:00 )',
( run in 0.482 second using v1.01-cache-2.11-cpan-9581c071862 )