Created
July 8, 2020 19:15
-
-
Save chandlerkent/19379407065c40910d930ce95b04063b to your computer and use it in GitHub Desktop.
aprimo-playground
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
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}`; | |
} | |
} | |
} |
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
{ | |
"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