shalugin/horizontal-timeline

unable to load data

bobingham opened this issue · 1 comments

I have a problem loading data. I fire the loadTimeline method after I have received data from the server. If I build the TimelineElement array manually everything works fine. If I load by pushing new objects into the array I get the following error:

ERROR TypeError: Failed to execute 'getComputedStyle' on 'Window': parameter 1 is not of type 'Element'.

  loadTimeline(carePlanSections: NcCarePlanDto[]) {
    this.timeline = [];
    setTimeout(() => { // simulate delay 
      carePlanSections.forEach((section) => {
        this.timeline.push({ caption: 'fromNow', date: moment(section.reviewDatetime).toDate(), selected: false, title: section.subject, content: section.editor })
      })
    //   this.timeline = [
    //     { caption: '16 Jan', date: moment(carePlanSections[0].createdDatetime).toDate(), title: 'Horizontal Timeline', content: this.content },
    //     { caption: '28 Feb', date: new Date(2014, 2, 28), title: 'Status#1', content: this.content },
    //     { caption: '20 Mar', date: new Date(2014, 3, 20), selected: true, title: 'Status#2', content: this.content },
    //     { caption: '20 May', date: new Date(2014, 5, 20), title: 'Status#3', content: this.content },
    //     { caption: '09 Jul', date: new Date(2014, 7, 9), title: 'Status#4', content: this.content },
    //     { caption: '30 Aug', date: new Date(2014, 8, 30), title: 'Status#5', content: this.content },
    //     { caption: '15 Sep', date: new Date(2014, 9, 15), title: 'Status#6', content: this.content },
    //     { caption: '01 Nov', date: new Date(2014, 11, 1), title: 'Status#7', content: this.content },
    //     { caption: '10 Dec', date: new Date(2014, 12, 10), title: 'Status#8', content: this.content },
    //     { caption: '29 Jan', date: new Date(2015, 1, 19), title: 'Status#9', content: this.content },
    //     { caption: '3 Mar', date: new Date(2015, 3, 3), title: 'Status#9', content: this.content },
    //   ];
    }, 2000);
  }

My bad,
One element in the array must be selected. Not quite clear on the instructions!

  loadTimeline(carePlanSections: NcCarePlanDto[]) {
    this.timeline = [];
      let selected = false;
      carePlanSections.forEach((section, key, arr) => {
        if (Object.is(arr.length - 1, key)) {
          selected = true; // execute last item logic
        }
       this.timeline.push({ caption: section.subject, date: moment(section.reviewDatetime).toDate(), title: section.subject, selected: selected, content: section.editor })
      })
  }