-
Notifications
You must be signed in to change notification settings - Fork 903
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 #2701 from icfantv/execution_window
(core) add day selector to execution window
- Loading branch information
Showing
10 changed files
with
250 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
{ | ||
"ecmaFeatures": { | ||
"jsx": false, | ||
"modules": true, | ||
}, | ||
"extends": "eslint:recommended", | ||
"rules": { | ||
|
90 changes: 90 additions & 0 deletions
90
...es/core/pipeline/config/stages/executionWindows/ExecutionWindowDayPickerComponent.spec.js
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { DAYS_OF_WEEK} from './daysOfWeek'; | ||
|
||
describe('Component: Execution Window Day Picker', () => { | ||
|
||
let $componentController; | ||
beforeEach(window.module(require('./executionWindowDayPicker.component.js'))); | ||
beforeEach(window.inject((_$componentController_) => $componentController = _$componentController_)); | ||
|
||
function constructController(bindings) { | ||
return $componentController('executionWindowDayPicker', null, bindings); | ||
} | ||
|
||
it('should not have any days selected when the days property is not defined', () => { | ||
const ctrl = constructController({days: undefined}); | ||
expect(ctrl.days).toBeUndefined(); | ||
}); | ||
|
||
it('should not have any days selected when the days property is null', () => { | ||
const ctrl = constructController({days: null}); | ||
expect(ctrl.days).toBe(null); | ||
}); | ||
|
||
it('should not have any days selected when the days property is an empty array', () => { | ||
const ctrl = constructController({days: []}); | ||
expect(ctrl.days.length).toBe(0); | ||
}); | ||
|
||
DAYS_OF_WEEK.forEach((day) => { | ||
it(`should have ${day.key} selected when the days property contains ${day.ordinal}`, () => { | ||
const ctrl = constructController({days: [day.ordinal]}); | ||
expect(ctrl.days.length).toBe(1); | ||
expect(ctrl.days[0]).toBe(day.ordinal); | ||
}); | ||
}); | ||
|
||
it('should select all the days when the all button is clicked', () => { | ||
const ctrl = constructController({}); | ||
ctrl.all(); | ||
expect(ctrl.days.length).toBe(7); | ||
}); | ||
|
||
it('should select none of the days when the none button is clicked', () => { | ||
const ctrl = constructController({}); | ||
ctrl.all(); | ||
expect(ctrl.days.length).toBe(7); | ||
ctrl.none(); | ||
expect(ctrl.days.length).toBe(0); | ||
}); | ||
|
||
it('should select just the weekdays when the weekday button is clicked', () => { | ||
const ctrl = constructController({}); | ||
ctrl.weekdays(); | ||
expect(ctrl.days.length).toBe(5); | ||
expect(ctrl.days).toEqual([2,3,4,5,6]); | ||
}); | ||
|
||
it('should select just the weekend when the weekend button is clicked', () => { | ||
const ctrl = constructController({}); | ||
ctrl.weekend(); | ||
expect(ctrl.days.length).toBe(2); | ||
expect(ctrl.days[0]).toBe(1); // sunday | ||
expect(ctrl.days[1]).toBe(7); // saturday | ||
}); | ||
|
||
it('should specify whether or not a day is selected', () => { | ||
const ctrl = constructController({ | ||
days: [1] | ||
}); | ||
expect(ctrl.daySelected(1)).toBe(true); | ||
expect(ctrl.daySelected(2)).toBe(false); | ||
|
||
ctrl.days = [1, 2]; | ||
expect(ctrl.daySelected(2)).toBe(true); | ||
expect(ctrl.daySelected(3)).toBe(false); | ||
}); | ||
|
||
it('should add a day to the model when selected', () => { | ||
const ctrl = constructController({}); | ||
ctrl.updateModel(DAYS_OF_WEEK[0]); | ||
expect(ctrl.daySelected(1)).toBe(true); | ||
}); | ||
|
||
it('should remove a day from the model when unselected', () => { | ||
const ctrl = constructController({ | ||
days: [1] // pre-select sunday | ||
}); | ||
ctrl.updateModel(DAYS_OF_WEEK[0]); | ||
expect(ctrl.daySelected(1)).toBe(false); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
app/scripts/modules/core/pipeline/config/stages/executionWindows/daysOfWeek.js
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 |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export const DAYS_OF_WEEK = [ | ||
{ | ||
key: 'sunday', | ||
label: 'Sun', | ||
ordinal: 1 | ||
}, { | ||
key: 'monday', | ||
label: 'Mon', | ||
ordinal: 2 | ||
}, { | ||
key: 'tuesday', | ||
label: 'Tue', | ||
ordinal: 3 | ||
}, { | ||
key: 'wednesday', | ||
label: 'Wed', | ||
ordinal: 4 | ||
}, { | ||
key: 'thursday', | ||
label: 'Thu', | ||
ordinal: 5 | ||
}, { | ||
key: 'friday', | ||
label: 'Fri', | ||
ordinal: 6 | ||
}, { | ||
key: 'saturday', | ||
label: 'Sat', | ||
ordinal: 7 | ||
} | ||
]; |
13 changes: 13 additions & 0 deletions
13
...ules/core/pipeline/config/stages/executionWindows/executionWindowDayPicker.component.html
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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<div class="btn-group"> | ||
<button ng-repeat="day in ::$ctrl.DAYS_OF_WEEK" | ||
type="button" | ||
class="btn btn-default" | ||
ng-click="$ctrl.updateModel(day)" | ||
ng-class="{ active: $ctrl.daySelected(day.ordinal) }">{{ ::day.label }}</button> | ||
</div> | ||
<div class="button-controls"> | ||
<span class="btn btn-link" ng-click="$ctrl.all()">All</span> | ||
<span class="btn btn-link" ng-click="$ctrl.none()">None</span> | ||
<span class="btn btn-link" ng-click="$ctrl.weekdays()">Weekdays</span> | ||
<span class="btn btn-link" ng-click="$ctrl.weekend()">Weekend</span> | ||
</div> |
55 changes: 55 additions & 0 deletions
55
...odules/core/pipeline/config/stages/executionWindows/executionWindowDayPicker.component.js
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 |
---|---|---|
@@ -0,0 +1,55 @@ | ||
const angular = require('angular'); | ||
|
||
import { DAYS_OF_WEEK } from './daysOfWeek'; | ||
|
||
class ExecutionWindowDayPickerController { | ||
|
||
constructor() { | ||
this.DAYS_OF_WEEK = DAYS_OF_WEEK; | ||
} | ||
|
||
daySelected(ordinal) { | ||
const days = new Set(this.days); | ||
return days.has(ordinal); | ||
} | ||
|
||
all() { | ||
this.days = [1, 2, 3, 4, 5, 6, 7]; | ||
} | ||
|
||
none() { | ||
this.days = []; | ||
} | ||
|
||
weekdays() { | ||
this.days = [2, 3, 4, 5, 6]; | ||
} | ||
|
||
weekend() { | ||
this.days = [1, 7]; | ||
} | ||
|
||
updateModel(day) { | ||
|
||
if (!this.days) { | ||
this.days = []; // for pre-existing pipelines, the 'days' property will not exist | ||
} | ||
|
||
const days = new Set(this.days); | ||
if (days.has(day.ordinal)) { | ||
this.days = this.days.filter((_day) => _day !== day.ordinal); | ||
} | ||
else { | ||
this.days.push(day.ordinal); | ||
} | ||
} | ||
} | ||
|
||
module.exports = angular.module('spinnaker.core.pipeline.stage.executionWindows.dayPicker', []) | ||
.component('executionWindowDayPicker', { | ||
bindings: { | ||
days: '=' | ||
}, | ||
controller: ExecutionWindowDayPickerController, | ||
templateUrl: require('./executionWindowDayPicker.component.html') | ||
}); |
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
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
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