-
Notifications
You must be signed in to change notification settings - Fork 53
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 #588 from HSF/sponce_cycleEnhancement
Auto reload feature for cycle-event component
- Loading branch information
Showing
8 changed files
with
280 additions
and
116 deletions.
There are no files selected for viewing
17 changes: 13 additions & 4 deletions
17
...cts/phoenix-ui-components/lib/components/ui-menu/cycle-events/cycle-events.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 |
---|---|---|
@@ -1,7 +1,16 @@ | ||
<app-menu-toggle | ||
<button | ||
class="cycle-events" | ||
[ngClass]="" | ||
[matTooltip]="tooltip" | ||
matTooltipPosition="above" | ||
matTooltipTouchGestures="off" | ||
tooltip="Cycle through events" | ||
[active]="active" | ||
icon="cycle-events" | ||
(click)="toggleCycle()" | ||
> | ||
</app-menu-toggle> | ||
<svg | ||
class="cycle-events-icon" | ||
[ngClass]="{ 'active-icon': active, 'reload-icon': reloading }" | ||
> | ||
<use href="assets/icons/cycle-events.svg#cycle-events"></use> | ||
</svg> | ||
</button> |
41 changes: 41 additions & 0 deletions
41
...cts/phoenix-ui-components/lib/components/ui-menu/cycle-events/cycle-events.component.scss
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,41 @@ | ||
:host { | ||
display: flex; | ||
margin: 0 0.6rem; | ||
|
||
.cycle-events { | ||
display: flex; | ||
background: unset; | ||
border: none; | ||
height: 2.5rem; | ||
width: 2.5rem; | ||
min-height: 2.5rem; | ||
min-width: 2.5rem; | ||
padding: 0.65rem; | ||
cursor: pointer; | ||
align-self: center; | ||
transition: all 0.4s; | ||
|
||
&-icon { | ||
width: 100%; | ||
height: 100%; | ||
|
||
&.active-icon { | ||
--phoenix-options-icon-path: #00bcd4; | ||
} | ||
&.reload-icon { | ||
--phoenix-options-icon-path: #77dd77; | ||
} | ||
} | ||
|
||
&:hover { | ||
background-color: var(--phoenix-options-icon-bg); | ||
border-radius: 40%; | ||
transition: all 0.4s; | ||
} | ||
|
||
&.disabled { | ||
cursor: not-allowed; | ||
opacity: 0.4; | ||
} | ||
} | ||
} |
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
50 changes: 40 additions & 10 deletions
50
...jects/phoenix-ui-components/lib/components/ui-menu/cycle-events/cycle-events.component.ts
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,43 +1,73 @@ | ||
import { Component, Input, OnInit } from '@angular/core'; | ||
import { EventDisplayService } from '../../../services/event-display.service'; | ||
import { FileLoaderService } from '../../../services/file-loader.service'; | ||
|
||
@Component({ | ||
selector: 'app-cycle-events', | ||
templateUrl: './cycle-events.component.html', | ||
styleUrls: ['./cycle-events.component.scss'], | ||
}) | ||
export class CycleEventsComponent implements OnInit { | ||
@Input() | ||
interval: number; | ||
@Input() interval: number; | ||
@Input() tooltip: string; | ||
@Input() icon: string; | ||
|
||
// There are actually 3 states we go through when clicking this component : | ||
// - not active : so we are not cycling throught events | ||
// - active and not reloading : cycling over the events stored in events | ||
// - active and reloading : cycling and reloading the events when reaching the end | ||
// Last state is useful e.g. for live feed of events | ||
active: boolean = false; | ||
reloading: boolean = false; | ||
|
||
private intervalId: NodeJS.Timer; | ||
|
||
private events: string[]; | ||
|
||
constructor(private eventDisplay: EventDisplayService) {} | ||
constructor( | ||
private eventDisplay: EventDisplayService, | ||
private fileLoader: FileLoaderService | ||
) {} | ||
|
||
ngOnInit() { | ||
this.eventDisplay.listenToLoadedEventsChange( | ||
(events) => (this.events = events) | ||
); | ||
this.eventDisplay.listenToLoadedEventsChange((events) => { | ||
this.events = events; | ||
if (this.active) { | ||
// restart cycling from first event | ||
clearInterval(this.intervalId); | ||
this.startCycleInterval(); | ||
} | ||
}); | ||
} | ||
|
||
toggleCycle() { | ||
this.active = !this.active; | ||
this.reloading = this.active && !this.reloading; | ||
this.active = !this.active || this.reloading; | ||
console.log(this.active, this.reloading); | ||
clearInterval(this.intervalId); | ||
|
||
if (this.active) { | ||
this.startCycleInterval(); | ||
} | ||
} | ||
|
||
private startCycleInterval(startIndex: number = 0) { | ||
// load immediately first event | ||
let index = startIndex; | ||
|
||
this.eventDisplay.loadEvent(this.events[index]); | ||
index = index + 1 >= this.events.length ? -1 : index + 1; | ||
// launch automatic cycling | ||
this.intervalId = setInterval(() => { | ||
index = index >= this.events.length ? 0 : index + 1; | ||
// special value -1 is used to denote wrapping of the current set of events | ||
if (index == -1) { | ||
if (this.reloading) { | ||
// reload the current events | ||
this.fileLoader.reloadLastEvents(this.eventDisplay); | ||
} | ||
// put back index to 0 to start with first event anyway | ||
index = 0; | ||
} | ||
this.eventDisplay.loadEvent(this.events[index]); | ||
index = index + 1 >= this.events.length ? -1 : index + 1; | ||
}, this.interval); | ||
} | ||
} |
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
Oops, something went wrong.