Skip to content

Instantly share code, notes, and snippets.

@chandlerkent
Created July 8, 2020 19:15
Show Gist options
  • Save chandlerkent/19379407065c40910d930ce95b04063b to your computer and use it in GitHub Desktop.
Save chandlerkent/19379407065c40910d930ce95b04063b to your computer and use it in GitHub Desktop.
aprimo-playground
import Controller from '@ember/controller';
import { tracked } from '@glimmer/tracking';
const RECURRING_FREQUENCY_UNIT = {
2: "Hourly",
3: "Daily",
4: "Weekly",
5: "Monthly"
};
const RECURRING_OPTIONS = {
2: {
0: "hours",
1: "minutes"
},
3: {
0: "every day",
1: "weekdays"
}
};
const MONTHLY_RECURRING_WEEKS = {
0: "first",
1: "second",
2: "third",
3: "fourth",
4: "last"
};
const MONTHLY_RECURRING_DAYS = {
0: "Monday",
1: "Tuesday",
2: "Wednesday",
3: "Thursday",
4: "Friday",
5: "Saturday",
6: "Sunday",
7: "day",
8: "week day",
9: "weekend day"
};
export default class ApplicationController extends Controller {
@tracked recurring_frequency_unit = 5;
@tracked recurring_frequency = 0;
@tracked recurring_option_1 = 0;
@tracked recurring_option_2 = 0;
@tracked recurring_option_3 = 0;
@tracked recurring_option_4 = 0;
@tracked recurring_option_5 = 0;
@tracked recurring_option_6 = 0;
@tracked recurring_option_7 = 0;
get displayString() {
let prefix = `Repeats ${RECURRING_FREQUENCY_UNIT[this.recurring_frequency_unit]},`
switch (+this.recurring_frequency_unit) {
case 2: {
return `${prefix} every ${this.recurring_frequency} ${RECURRING_OPTIONS[this.recurring_frequency_unit][this.recurring_option_1]}`;
}
case 3: {
return `${prefix} ${RECURRING_OPTIONS[this.recurring_frequency_unit][this.recurring_option_1]}`;
}
case 4: {
let days = [];
if (this.recurring_option_1 == 1) {
days.push("Monday");
}
if (this.recurring_option_2 == 1) {
days.push("Tuesday");
}
if (this.recurring_option_3 == 1) {
days.push("Wednesday");
}
if (this.recurring_option_4 == 1) {
days.push("Thursday");
}
if (this.recurring_option_5 == 1) {
days.push("Friday");
}
if (this.recurring_option_6 == 1) {
days.push("Saturday");
}
if (this.recurring_option_7 == 1) {
days.push("Sunday");
}
return `${prefix} every ${this.recurring_frequency} weeks on ${days.join(", ")}`;
}
case 5: {
switch (+this.recurring_option_1) {
case 0: {
return `${prefix} on day ${this.recurring_option_2} of every ${this.recurring_frequency} months`;
}
case 1: {
return `${prefix} on ${MONTHLY_RECURRING_WEEKS[this.recurring_option_3]} ${MONTHLY_RECURRING_DAYS[this.recurring_option_4]} of every ${this.recurring_frequency} months`;
}
default:
return `Unhandled recurring_option_1: ${this.recurring_option_1}.`
}
return `${prefix}`;
}
default:
return `Unhandled frequency unit: ${this.recurring_frequency_unit}`;
}
}
}
<h1>Aprimo Schedule Job Playground</h1>
<form>
<div>
<label for="recurring_frequency_unit">recurring_frequency_unit</label>
<Input type="number" id="recurring_frequency_unit" @value={{this.recurring_frequency_unit}} />
</div>
<div>
<label for="recurring_frequency">recurring_frequency</label>
<Input type="number" id="recurring_frequency" @value={{this.recurring_frequency}} />
</div>
<div>
<label for="recurring_option_1">recurring_option_1</label>
<Input type="number" id="recurring_option_1" @value={{this.recurring_option_1}} />
</div>
<div>
<label for="recurring_option_2">recurring_option_2</label>
<Input type="number" id="recurring_option_2" @value={{this.recurring_option_2}} />
</div>
<div>
<label for="recurring_option_3">recurring_option_3</label>
<Input type="number" id="recurring_option_3" @value={{this.recurring_option_3}} />
</div>
<div>
<label for="recurring_option_4">recurring_option_4</label>
<Input type="number" id="recurring_option_4" @value={{this.recurring_option_4}} />
</div>
<div>
<label for="recurring_option_5">recurring_option_5</label>
<Input type="number" id="recurring_option_5" @value={{this.recurring_option_5}} />
</div>
<div>
<label for="recurring_option_6">recurring_option_6</label>
<Input type="number" id="recurring_option_6" @value={{this.recurring_option_6}} />
</div>
<div>
<label for="recurring_option_7">recurring_option_7</label>
<Input type="number" id="recurring_option_7" @value={{this.recurring_option_7}} />
</div>
</form>
<h2>Output</h2>
<p>{{this.displayString}}</p>
{
"version": "0.17.1",
"EmberENV": {
"FEATURES": {},
"_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true,
"_APPLICATION_TEMPLATE_WRAPPER": false,
"_JQUERY_INTEGRATION": false
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"ember": "3.18.1",
"ember-template-compiler": "3.18.1",
"ember-testing": "3.18.1"
},
"addons": {
"@glimmer/component": "1.0.0"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment