Add a comment

This commit is contained in:
Simon Hanna 2018-08-30 00:04:05 +02:00
parent 1dedb80ad5
commit a083bea652
1 changed files with 17 additions and 3 deletions

View File

@ -40,10 +40,21 @@ export class StageViewComponent implements OnInit {
}
this.currentSlides = slides;
this.activeSlide = slides.findIndex(s => s.selected);
this.updateOrderOfTags();
this.updateTags();
}
updateOrderOfTags(): void {
/**
* This method updates the tags from the current slides.
*
* We add a tag as soon as we know we need it.
* So we start with the first tag and on each tag change we push the new one.
*
* If we find the same tag, we check to see if the current slide is a repition.
* In case of a repition we also add a new tag.
*
* TODO This approach should work for most cases. It is a primary candidate for a test :-)
*/
updateTags(): void {
this.tags = [];
this.tags.push({"text": this.currentSlides[0].tag, "active": this.currentSlides[0].selected});
let lastIndex : number = 0;
@ -53,8 +64,11 @@ export class StageViewComponent implements OnInit {
if (this.currentSlides[index].tag == this.currentSlides[lastIndex].tag) {
for (let i = 0; i < index - lastIndex; ++i) {
foundActive = foundActive || this.currentSlides[index + i].selected;
// they are different, stop checking and continue outer loop
if (this.currentSlides[lastIndex + i].text != this.currentSlides[index + i].text) {
// they are different, stop checking and continue outer loop
// Since we are collapsing tags, we make sure to mark the tag active, if any of the collapsed tags were active
if (foundActive) {
this.tags[this.tags.length - 1].active = foundActive;
}