Best JavaScript code snippet using root
ViewMonthList.js
Source:ViewMonthList.js
1/**2 * This software is free software; you can redistribute it and/or3 * modify it under the terms of the GNU Lesser General Public4 * License version 3 as published by the Free Software Foundation5 *6 * This library is distributed in the hope that it will be useful,7 * but WITHOUT ANY WARRANTY; without even the implied warranty of8 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU9 * Lesser General Public License for more details.10 *11 * @category PHProjekt12 * @package Application13 * @subpackage Calendar214 * @copyright Copyright (c) 2010 Mayflower GmbH (http://www.mayflower.de)15 * @license LGPL v3 (See LICENSE file)16 * @link http://www.phprojekt.com17 * @since File available since Release 6.118 * @author Mariano La Penna <mariano.lapenna@mayflower.de>19 */20dojo.provide("phpr.Calendar2.ViewMonthList");21dojo.declare("phpr.Calendar2.ViewMonthList", phpr.Calendar2.DefaultView, {22 // Summary:23 // Class for displaying a Calendar2 Month List24 // description:25 // This Class takes care of displaying the list information we receive from our Server in a HTML table26 _header: Array(7),27 _scrollLastDirection: 0,28 COLOR_WEEKDAY: '#FFFFFF',29 COLOR_WEEKEND: '#EFEFEF',30 COLOR_TODAY: '#DEEBF7',31 COLOR_OUT_OF_MONTH: '#DEDFDE',32 beforeConstructor: function() {33 // Summary:34 // Calls the schedule array basic filling function, before constructor function35 this.fillScheduleArrayPart1();36 },37 afterConstructor: function() {38 // Summary:39 // Loads the data from the database40 phpr.DataStore.addStore({url: this.url, noCache: true});41 phpr.DataStore.requestData({url: this.url, processData: dojo.hitch(this, "onLoaded")});42 },43 setUrl: function() {44 // Summary:45 // Sets the url to get the data from46 this.url = 'index.php/' + phpr.module + '/index/jsonPeriodList/dateStart/' +47 this._schedule[0][0].date + '/dateEnd/' + this._schedule[this._schedule.length - 1][6].date +48 '/userId/' + this.main.getActiveUser().id;49 },50 onLoaded: function(dataContent) {51 // Summary:52 // This function is called when the request to the DB is received53 // Description:54 // It parses that json info and prepares an apropriate array so that the template can render55 // appropriately the TABLE html element.56 if (this._destroyed) {57 return;58 }59 var meta = phpr.DataStore.getMetaData({url: this.url});60 // Render export Button?61 this.setExportButton(meta);62 var content = phpr.DataStore.getData({url: this.url});63 this.fillHeaderArray();64 // Fill the main array with the data of the events65 this.fillScheduleArrayPart2(content);66 // All done, let's render the template67 phpr.viewManager.getView().gridContainer.set('content',68 phpr.fillTemplate("phpr.Calendar2.template.monthList.html", {69 widthTable: this._widthTable,70 header: this._header,71 schedule: this._schedule72 }73 ));74 dojo.publish('Calendar2.connectMouseScroll');75 },76 exportData: function() {77 // Summary:78 // Opens a new window in CSV mode79 var dateTemp = phpr.date.isoDateTojsDate(this._date);80 dateTemp.setDate(1);81 var firstDayMonth = phpr.date.getIsoDate(dateTemp);82 var daysInMonth = dojo.date.getDaysInMonth(dateTemp);83 dateTemp.setDate(daysInMonth);84 var lastDayMonth = phpr.date.getIsoDate(dateTemp);85 window.open('index.php/' + phpr.module + '/index/csvPeriodList/nodeId/1/dateStart/' +86 firstDayMonth + '/dateEnd/' + lastDayMonth + '/csrfToken/' + phpr.csrfToken);87 return false;88 },89 fillScheduleArrayPart1: function() {90 // Summary:91 // Fills the schedule array with the basic structure and data of every day of the calendar month table.92 // It includes not only the days of this month but the necessary days of the previous and next month in93 // order to fill 4 or 6 week rows, from Monday to Sunday.94 var today = new Date();95 today = phpr.date.getIsoDate(today);96 // First dimension is each row shown, the amount of rows depends on each month:97 this._schedule = [];98 var dateTemp = phpr.date.isoDateTojsDate(this._date);99 var daysInMonth = dojo.date.getDaysInMonth(dateTemp);100 dateTemp.setDate(1);101 var firstDayDiff = dateTemp.getDay() - 1;102 if (firstDayDiff == -1) {103 firstDayDiff = 6;104 }105 var firstDayShown = dojo.date.add(dateTemp, 'day', - firstDayDiff);106 dateTemp.setDate(daysInMonth);107 var lastDayShown = dojo.date.add(dateTemp, 'day', (7 - dateTemp.getDay()));108 var totalRows = (dojo.date.difference(firstDayShown, lastDayShown, 'day') + 1) / 7;109 // For every row110 for (var i = 0; i < totalRows; i ++) {111 this._schedule[i] = new Array(7);112 // For every day of the week113 for (var j = 0; j < 7; j ++) {114 this._schedule[i][j] = [];115 dateTemp = dojo.date.add(firstDayShown, 'day', (i * 7) + j);116 this._schedule[i][j].day = dateTemp.getDate();117 this._schedule[i][j].date = phpr.date.getIsoDate(dateTemp);118 if (this._schedule[i][j].date == today) {119 this._schedule[i][j].color = this.COLOR_TODAY;120 } else if (((i === 0) && (this._schedule[i][j].day > 22)) ||121 ((i > 3) && (this._schedule[i][j].day < 7))) {122 this._schedule[i][j].color = this.COLOR_OUT_OF_MONTH;123 } else if (j < 5) {124 this._schedule[i][j].color = this.COLOR_WEEKDAY;125 } else {126 this._schedule[i][j].color = this.COLOR_WEEKEND;127 }128 }129 }130 },131 fillHeaderArray: function() {132 // Summary:133 // Fills the header array with the main row of the table.134 this._header.columnsWidth = Math.floor((100 - this._widthHourColumn) / 7);135 this._header.days = [];136 this._header.days[0] = phpr.nls.get('Monday');137 this._header.days[1] = phpr.nls.get('Tuesday');138 this._header.days[2] = phpr.nls.get('Wednesday');139 this._header.days[3] = phpr.nls.get('Thursday');140 this._header.days[4] = phpr.nls.get('Friday');141 this._header.days[5] = phpr.nls.get('Saturday');142 this._header.days[6] = phpr.nls.get('Sunday');143 },144 fillScheduleArrayPart2: function(content) {145 // Summary:146 // Puts every event in the corresponding array position.147 for (var event in content) {148 // Split datetime in date and time149 var dateTime = phpr.date.isoDatetimeTojsDate(content[event].start);150 content[event].startDate = phpr.date.getIsoDate(dateTime);151 content[event].startTime = phpr.date.getIsoTime(dateTime);152 dateTime = phpr.date.isoDatetimeTojsDate(content[event].end);153 content[event].endDate = phpr.date.getIsoDate(dateTime);154 content[event].endTime = phpr.date.getIsoTime(dateTime);155 var warning = '';156 var currentUserId = content[event].rights[this.main.getActiveUser().id].userId;157 if (currentUserId == content[event].ownerId) {158 // This is our event, let's add a warning if somebody has not159 // accepted (or beware, somebody rejected!) our invitation.160 for (var p in content[event].confirmationStatuses) {161 var status = content[event].confirmationStatuses[p];162 if (1 == status) { // Pending163 warning = '<img src="css/themes/phprojekt/images/help.gif"' + ' title="' +164 phpr.nls.get('Some participants have not accepted yet.') + '"/>';165 } else if (3 == status) { //Rejected166 warning = '<img src="css/themes/phprojekt/images/warning.png"' +167 ' title="' + phpr.nls.get('Some participants have rejected your invitation.') + '"/>';168 // Break to prevent warning from being overwritten if169 // someone after this participant is pending.170 break;171 }172 }173 } else {174 // We're just invited. Let's remind the user if we didn't175 // respond yet.176 if (content[event].confirmationStatus == 1) {177 warning = '<img src="css/themes/phprojekt/images/help.gif"' + ' title="' +178 phpr.nls.get('You did not respond to this invitation yet.') + '"/>';179 }180 }181 for (var row in this._schedule) {182 for (var weekDay in this._schedule[row]) {183 var eventInfo = this.getEventInfo(content[event].startDate, content[event].startTime,184 content[event].endDate, content[event].endTime, this._schedule[row][weekDay].date);185 if (eventInfo.range == this.SHOWN_INSIDE_CHART) {186 if (typeof(this._schedule[row][weekDay].events) == 'undefined') {187 this._schedule[row][weekDay].events = [];188 }189 var nextEvent = this._schedule[row][weekDay].events.length;190 var contentTitle = content[event].summary;191 this._schedule[row][weekDay].events[nextEvent] = [];192 this._schedule[row][weekDay].events[nextEvent].id = content[event].id;193 this._schedule[row][weekDay].events[nextEvent].summary = this.htmlEntities(contentTitle);194 this._schedule[row][weekDay].events[nextEvent].time = eventInfo.time;195 this._schedule[row][weekDay].events[nextEvent].start = content[event].start;196 this._schedule[row][weekDay].events[nextEvent].occurrence = content[event].occurrence;197 this._schedule[row][weekDay].events[nextEvent].warning = warning;198 }199 }200 }201 }202 var sortFunc = function(a, b) {203 a = phpr.date.isoDatetimeTojsDate(a.start);204 b = phpr.date.isoDatetimeTojsDate(b.start);205 return a - b;206 };207 for (var row in this._schedule) {208 for (var day in this._schedule[row]) {209 if (this._schedule[row][day].events !== undefined) {210 this._schedule[row][day].events.sort(sortFunc);211 }212 }213 }214 },215 getEventInfo: function(/*string*/ eventStartDate_String, /*string*/ eventStartTime_String,216 /*string*/ eventEndDate_String, /*string*/ eventEndTime_String,217 /*string*/ momentAskedDate) {218 // Summary:219 // Returns useful data about an event, used to create the schedule table.220 var result = []; // The variable that will be returned221 var eventStart_Date = new Date(); // Date and time the event starts222 var eventEnd_Date = new Date(); // Date and time the event ends223 var momentAsked_Date = new Date(); // momentAsked (with or without time)224 var eventStartDay_Date = new Date(); // Just the year/month/day of the event start225 var eventEndDay_Date = new Date(); // Just the year/month/day of the event end226 // Convert strings variables into date ones227 temp = eventStartDate_String.split('-');228 var eventStartYear = parseInt(temp[0], 10);229 var eventStartMonth = parseInt(temp[1], 10);230 var eventStartDay = parseInt(temp[2], 10);231 temp = eventEndDate_String.split('-');232 var eventEndYear = parseInt(temp[0], 10);233 var eventEndMonth = parseInt(temp[1], 10);234 var eventEndDay = parseInt(temp[2], 10);235 var temp = momentAskedDate.split('-');236 var momentAskedYear = parseInt(temp[0], 10);237 var momentAskedMonth = parseInt(temp[1], 10);238 var momentAskedDay = parseInt(temp[2], 10);239 eventStartDay_Date.setFullYear(eventStartYear, eventStartMonth - 1, eventStartDay);240 eventStartDay_Date.setHours(0, 0, 0, 0);241 eventEndDay_Date.setFullYear(eventEndYear, eventEndMonth - 1, eventEndDay);242 eventEndDay_Date.setHours(0, 0, 0, 0);243 momentAsked_Date.setFullYear(momentAskedYear, momentAskedMonth - 1, momentAskedDay);244 momentAsked_Date.setHours(0, 0, 0, 0);245 // Has the event to be shown for the day received (momentAskedDate)?246 if ((dojo.date.compare(eventStartDay_Date, momentAsked_Date) <= 0) &&247 (dojo.date.compare(eventEndDay_Date, momentAsked_Date) >= 0)) {248 // Yes249 result.range = this.SHOWN_INSIDE_CHART;250 temp = eventStartTime_String.split(':');251 var eventStartHour = parseInt(temp[0], 10);252 var eventStartMinutes = parseInt(temp[1], 10);253 temp = eventEndTime_String.split(':');254 var eventEndHour = parseInt(temp[0], 10);255 var eventEndMinutes = parseInt(temp[1], 10);256 temp = momentAskedDate.split('-');257 eventStart_Date.setFullYear(eventStartYear, eventStartMonth - 1, eventStartDay);258 eventStart_Date.setHours(eventStartHour, eventStartMinutes, 0, 0);259 eventEnd_Date.setFullYear(eventEndYear, eventEndMonth - 1, eventEndDay);260 eventEnd_Date.setHours(eventEndHour, eventEndMinutes, 0, 0);261 // Time description262 if ((dojo.date.compare(eventStartDay_Date, momentAsked_Date) < 0) &&263 (dojo.date.compare(eventEndDay_Date, momentAsked_Date) > 0)) {264 result.time = this.eventDateTimeDescrip(this.DATETIME_MULTIDAY_MIDDLE);265 } else if (dojo.date.compare(eventEndDay_Date, momentAsked_Date) > 0) {266 result.time = this.eventDateTimeDescrip(this.DATETIME_MULTIDAY_START, eventStartTime_String);267 } else if (dojo.date.compare(eventStartDay_Date, momentAsked_Date) < 0) {268 result.time = this.eventDateTimeDescrip(this.DATETIME_MULTIDAY_END, null, eventEndTime_String);269 } else {270 result.time = this.eventDateTimeDescrip(this.DATETIME_SHORT, eventStartTime_String,271 eventEndTime_String);272 }273 } else {274 // No275 result.range = this.SHOWN_NOT;276 }277 return result;278 }...
schedule-core-impl.ts
Source:schedule-core-impl.ts
1import { Schedule } from 'app-engine';2import cloneDeep from 'lodash/cloneDeep';3import {4 ScheduleCore,5 TzScheduleCore,6 UtcScheduleCore,7} from './schedule-core';8import { ScheduleAdapterService } from '../../providers/schedule-adapter-service';9export abstract class ScheduleCoreImpl implements ScheduleCore {10 protected _schedule;11 constructor(12 protected _sas: ScheduleAdapterService,13 ) { }14 public bind(val: Schedule) {15 this._schedule = cloneDeep(val);16 }17 get schedule(): Schedule {18 return this._schedule;19 }20 get name(): string {21 return this._schedule.name;22 }23 get start(): string {24 return this._schedule.start;25 }26 get end(): string {27 return this._schedule.end;28 }29 get days(): Array<number> {30 return this._schedule.days;31 }32 get active(): boolean {33 return !this.isOutOfDate && this._schedule.active === 1;34 }35 get activeUntil(): number {36 return this._schedule.active_until;37 }38 get esh(): Object {39 return this._schedule.esh;40 }41 get isOneShot(): boolean {42 return this._sas.isOneShot(this._schedule);43 }44 get isOutOfDate(): boolean {45 return this._sas.isOutOfDate(this._schedule);46 }47 get isValid(): boolean {48 const validSet = !!(49 this.days &&50 this.start !== '' &&51 this.end !== ''52 );53 return this.isOneShot ?54 validSet && this.days.length === 1 :55 validSet && this.days.length > 0;56 }57 protected setActiveUntil(utcSchedule: Schedule, executeNow: boolean): Schedule {58 return this._sas.setActiveUntil(utcSchedule, executeNow);59 }60 public toggleScheduleDay(day) {61 if (day > 7 || day < 1) return;62 const index = this.days.indexOf(day);63 if (index > -1) {64 this.days.splice(index, 1);65 } else {66 this.days.push(day);67 }68 }69 isOverlapping: boolean;70 public abstract setOneShot(enable: boolean);71}72export class TzScheduleCoreImpl extends ScheduleCoreImpl implements TzScheduleCore {73 private originDays: Array<number> = [];74 constructor(75 _s: ScheduleAdapterService,76 ) {77 super(_s);78 }79 get isOverlapping(): boolean {80 const offset = new Date().getTimezoneOffset();81 return this._sas.isOverlapping(this._sas.toUTCSchedule(this._schedule, offset));82 }83 public setOneShot(enable: boolean = false) {84 if (enable) {85 this.originDays = this.schedule.days;86 this.schedule.days = [new Date().getDay()];87 this.schedule.active_until = 1;88 } else {89 this.schedule.days = this.originDays;90 this.schedule.active_until = null;91 }92 }93 public toUtcSchedule(executeNow: boolean = false): Schedule {94 const offset = new Date().getTimezoneOffset();95 const utcSchedule = this._sas.toUTCSchedule(this._schedule, offset);96 return this.setActiveUntil(utcSchedule, executeNow);97 }98}99export class UtcScheduleCoreImpl extends ScheduleCoreImpl implements UtcScheduleCore {100 private originDays: Array<number> = [];101 constructor(102 _s: ScheduleAdapterService,103 ) {104 super(_s);105 }106 get isOverlapping(): boolean {107 return this._sas.isOverlapping(this._schedule);108 }109 public setOneShot(enable: boolean = false) {110 if (enable) {111 this.originDays = this.schedule.days;112 this.schedule.days = [new Date().getUTCDay()];113 this.schedule.active_until = 1;114 } else {115 this.schedule.days = this.originDays;116 this.schedule.active_until = null;117 }118 }119 public toTzSchedule(executeNow: boolean = false): Schedule {120 const offset = new Date().getTimezoneOffset();121 const utcSchedule = this.setActiveUntil(this._schedule, executeNow);122 return this._sas.toTimezoneSchedule(utcSchedule, offset);123 }...
Using AI Code Generation
1var Rx = require('rx');2Rx.Scheduler.root.schedule(function(state) {3 console.log('Hello World!');4 this.schedule(state + 1, 1000);5}, 1000, 0);6var Rx = require('rx');7Rx.Scheduler.immediate.schedule(function(state) {8 console.log('Hello World!');9 this.schedule(state + 1, 1000);10}, 1000, 0);11var Rx = require('rx');12Rx.Scheduler.currentThread.schedule(function(state) {13 console.log('Hello World!');14 this.schedule(state + 1, 1000);15}, 1000, 0);16var Rx = require('rx');17Rx.Scheduler.default.schedule(function(state) {18 console.log('Hello World!');19 this.schedule(state + 1, 1000);20}, 1000, 0);21var Rx = require('rx');22Rx.Scheduler.timeout.schedule(function(state) {23 console.log('Hello World!');24 this.schedule(state + 1, 1000);25}, 1000, 0);26var Rx = require('rx');27Rx.Scheduler.recursive.schedule(function(state) {28 console.log('Hello World!');29 this.schedule(state + 1, 1000);30}, 1000, 0);31var Rx = require('rx');32Rx.Scheduler.virtual.schedule(function(state) {33 console.log('Hello World!');34 this.schedule(state + 1, 1000);35}, 1000, 0);36var Rx = require('rx');37Rx.Scheduler.historical.schedule(function(state) {38 console.log('Hello World!');39 this.schedule(state + 1, 1000);40}, 1000, 0);41var Rx = require('rx');42Rx.Scheduler.test.schedule(function(state) {43 console.log('Hello World!');44 this.schedule(state + 1, 1000);45}, 1000, 0);
Using AI Code Generation
1var rootScheduler = require('rx').Scheduler;2var interval = rootScheduler._schedule(function(state) {3 console.log('interval', state);4 if (state < 10) {5 state++;6 interval(state);7 }8}, 1000, 0);
Using AI Code Generation
1var root = require('root');2root._schedule(function() {3 console.log("Hello World!");4}, 5000);5var root = require('root');6root._schedule(function() {7 console.log("Hello World!");8}, 5000);9var root = require('root');10root._schedule(function() {11 console.log("Hello World!");12}, 5000);13var root = require('root');14root._schedule(function() {15 console.log("Hello World!");16}, 5000);17var root = require('root');18root._schedule(function() {19 console.log("Hello World!");20}, 5000);21var root = require('root');22root._schedule(function() {23 console.log("Hello World!");24}, 5000);25var root = require('root');26root._schedule(function() {27 console.log("Hello World!");28}, 5000);29var root = require('root');30root._schedule(function() {31 console.log("Hello World!");32}, 5000);33var root = require('root');34root._schedule(function() {35 console.log("Hello World!");36}, 5000);37var root = require('root');38root._schedule(function() {39 console.log("Hello World!");40}, 5000);
Using AI Code Generation
1root._schedule(function() {2 console.log('hello');3}, 1000);4root._schedule(function() {5 console.log('hello');6}, 1000);
Using AI Code Generation
1var root = this;2root._schedule(function() {3 console.log("Hello World!");4}, 2000);5var root = this;6root._scheduleOnce(function() {7 console.log("Hello World!");8}, 2000);9var root = this;10root._schedule(function() {11 console.log("Hello World!");12}, 2000);13root._unschedule(function() {14 console.log("Hello World!");15});16var root = this;17root._schedule(function() {18 console.log("Hello World!");19}, 2000);20root._unscheduleAllCallbacks();21var root = this;22root._scheduleUpdate();23var root = this;24root._scheduleUpdateWithPriority(0);25var root = this;26root._scheduleUpdate();27root._unscheduleUpdate();28var root = this;29root._scheduleUpdateWithPriority(0);30var root = this;31root._scheduleUpdate();
Using AI Code Generation
1var root = require('root');2root._schedule(function(){3 console.log("Hello World");4}, 1000);5var root = require('root');6root._schedule(function(){7 console.log("Hello World");8}, 1000);9var root = require('root');10root._setImmediate(function(){11 console.log("Hello World");12});13var root = require('root');14var callback = function(){15 console.log("Hello World");16};17root._setImmediate(callback);18root._clearImmediate(callback);19var root = require('root');20var callback = function(){21 console.log("Hello World");22};23var interval = root._setInterval(callback, 1000);24root._clearInterval(interval);25var root = require('root');26var callback = function(){27 console.log("Hello World");28};29var timeout = root._setTimeout(callback, 1000);30root._clearTimeout(timeout);
Using AI Code Generation
1var root = require('./../root.js');2var test = function(){3 console.log('test');4};5root._schedule(test, 1000);6root._run();
Using AI Code Generation
1var job = {2 func: function() {3 }4}5root._schedule("0 0 * * *", job);6var job = {7 func: function() {8 }9}10root._scheduleOnce("0 0 * * *", job);11var job = {12 func: function() {13 }14}15root._scheduleOnceIn(16var job = {17 func: function() {18 }19}20root._schedule("0 0 * * *", job);21var job = {22 func: function() {23 }24}25root._scheduleOnce("0 0 * * *", job);26var job = {27 func: function() {28 }29}30root._scheduleOnceIn(
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!