<div class="enablevue">
    <newsandeventsblockcomponent id="newsandeventsblock" class="container newsandeventsblock border-top" v-cloak fetch-events-url="http://localhost:2000/production//KitModules/Calendar/Services/CalendarDataService.asmx/GetCalendar" event-image-height="300"
        event-image-width="300" event-default-city="" event-language-id="sv-SE" event-month-filter-count="6" event-page-size="20" event-preview-length="200" event-calendarpage-id="12418" fetch-news-url="http://localhost:2000/production//KitModules/News/Services/NewsDataService.asmx/GetNews"
        news-image-height="300" news-image-width="300" news-default-city="" news-language-id="sv-SE" news-month-filter-count="6" news-page-size="20" news-preview-length="200" news-newspage-id="122674">
        <div slot="header" class="row mb-md mt-xs">
            <div class="col-12 col-md-6">
                <h1 class="heading-level-2">Aktuellt på Mittuniversitetet</h1>
                <div class="d-block d-sm-none  pb-xs"></div>
            </div>
            <div class="col-12 col-md-6">
                <div class="d-flex flex-row h-100 align-items-center float-md-right float-sm-left">
                    <a class="" href="">
                        More events
                    </a>
                    <a class="ml-5" href="#">
                        More news
                    </a>
                </div>
            </div>
        </div>
    </newsandeventsblockcomponent>
</div>
<div class="enablevue">
    <newsandeventsblockcomponent id="newsandeventsblock" class="container newsandeventsblock border-top" v-cloak
        fetch-events-url="{{eventSettings.urlToService}}" event-image-height="{{eventSettings.ImageHeight}}"
        event-image-width="{{eventSettings.ImageWidth}}" event-default-city="{{eventSettings.DefaultCity}}"
        event-language-id="{{eventSettings.LanguageId}}" event-month-filter-count="{{eventSettings.MonthFilterCount}}"
        event-page-size="{{eventSettings.PageSize}}" event-preview-length="{{eventSettings.PreviewLength}}"
        event-calendarpage-id="{{eventSettings.CalendarPageId}}" fetch-news-url="{{newsSettings.urlToService}}"
        news-image-height="{{newsSettings.ImageHeight}}" news-image-width="{{newsSettings.ImageWidth}}"
        news-default-city="{{newsSettings.DefaultCity}}" news-language-id="{{newsSettings.LanguageId}}"
        news-month-filter-count="{{newsSettings.MonthFilterCount}}" news-page-size="{{newsSettings.PageSize}}"
        news-preview-length="{{newsSettings.PreviewLength}}" news-newspage-id="{{newsSettings.NewsPageId}}">
        <div slot="header" class="row mb-md mt-xs">
            <div class="col-12 col-md-6">
                <h1 class="heading-level-2">{{title.value}}</h1>
                <div class="d-block d-sm-none  pb-xs"></div>
            </div>
            <div class="col-12 col-md-6">
                <div class="d-flex flex-row h-100 align-items-center float-md-right float-sm-left">
                    <a class="" href="{{linkTextEvent.url}}">
                        {{linkTextEvents.value}}
                    </a>
                    <a class="ml-5" href="{{linkTextNews.url}}">
                        {{linkTextNews.value}}
                    </a>
                </div>
            </div>
        </div>
    </newsandeventsblockcomponent>
</div>
{
  "epiDivClass": "col-md-12",
  "title": {
    "value": "Aktuellt på Mittuniversitetet",
    "epiEditAttribute": ""
  },
  "linkTextEvents": {
    "value": "More events",
    "url": "#"
  },
  "linkTextNews": {
    "value": "More news",
    "url": "#"
  },
  "eventSettings": {
    "urlToService": "http://localhost:2000/production//KitModules/Calendar/Services/CalendarDataService.asmx/GetCalendar",
    "ImageHeight": 300,
    "ImageWidth": 300,
    "DefaultCity": "",
    "LanguageId": "sv-SE",
    "MonthFilterCount": 6,
    "PageSize": 20,
    "PreviewLength": 200,
    "CalendarPageId": 12418
  },
  "newsSettings": {
    "urlToService": "http://localhost:2000/production//KitModules/News/Services/NewsDataService.asmx/GetNews",
    "ImageHeight": 300,
    "ImageWidth": 300,
    "DefaultCity": "",
    "LanguageId": "sv-SE",
    "MonthFilterCount": 6,
    "NewsPageId": 122674,
    "PageSize": 20,
    "PreviewLength": 200
  }
}
  • Content:
    Vue.component("newsandeventsblockcomponent", {
      name: "newsandeventsblockcomponent",
      template: `
      <div >
      <slot name="header">
      
      </slot>
    
      <div class="row">
          <div class="col-12 col-md-4" v-for="i in 6" :key="i" v-if="loading">
              <article class="fake--article ">
                  <div class="fake--image loading"></div>
                  <div class="fake--title loading mt-xs mb-xs"></div>
                  <div class="fake--text  mb-xs">
                      <div class="loading"></div>
                      <div class="loading"></div>
                      <div class="loading"></div>
                  </div>
              </article>
          </div>
          <div class="col-12 col-md-4" v-for="(item, index) in items" :key="index" v-if="!loading && index <= 5">
              <article role="article">
                  <a :href="item.Url" class="article--image lazyload d-flex" v-if="item.ImageData" v-cloak
                      :data-bg="item.ImageData"
                      >
                      <div v-cloak class="caption " v-if="!item.CalendarPageId">
                          Nyhet
                      </div>
                      <div v-cloak class="caption " v-if="item.CalendarPageId">
                          \{{item.EventStartDate}}
                      </div>
                  </a>
                  <h2 class="heading-level-3"><a :href="item.Url">\{{item.Title}}</a></h2>
                  <p v-if="item.Intro">\{{item.Intro}}</p>
                  <div class="d-flex flex-row" v-if="item.CalendarPageId">
                      <p class="small-font">Uppdaterad: \{{item.ChangedDate}}.
                          <br>Start: \{{item.EventStartDate}} kl. \{{item.StartTime}}-\{{item.StopTime}}
                          <br>\{{item.City}}<span class="small-font" v-if="item.Location">, \{{item.Location}}</span></p>
    
                  </div>
                  <div v-else class="d-flex flex-row">
                      <p class="small-font">\{{item.PublishedDate}}</p>
                  </div>
              </article>
          </div>
    
      </div>
    </div>
      `,
      data() {
        return {
          url: "",
          loading: false,
          items: [],
          events: [],
          news: [],
          eventRequest: {
            request: {
              Settings: {
                IsInit: true,
                PageIndex: 0
              }
            }
          },
          newsRequest: {
            request: {
              Settings: {
                IsInit: true,
                PageIndex: 0
              }
            }
          }
        };
      },
      mounted() {
        if (document.getElementById("newsandeventsblock")) {
          this.waitForUrlBeforeFetch();
        }
      },
      methods: {
        isLoading(bool) {
          this.loading = bool;
        },
        async waitForUrlBeforeFetch() {
          if (document.getElementById("newsandeventsblock")) {
            this.isLoading(true);
            let page = document.getElementById("newsandeventsblock");
            if (page) {
              //Get Event Props
              let eventsUrl = page.getAttribute("fetch-events-url");
              let eventProps = {
                ImageHeight: page.getAttribute("event-image-height"),
                ImageWidth: page.getAttribute("event-image-width"),
                DefaultCity: page.getAttribute("event-default-city"),
                LanguageId: page.getAttribute("event-language-id"),
                MonthFilterCount: page.getAttribute("event-month-filter-count"),
                PageSize: page.getAttribute("event-page-size"),
                PreviewLength: page.getAttribute("event-preview-length"),
                CalendarPageId: page.getAttribute("event-calendarpage-id")
              };
    
              //Get News Props
              let newsUrl = page.getAttribute("fetch-news-url");
              let newsProps = {
                ImageHeight: page.getAttribute("news-image-height"),
                ImageWidth: page.getAttribute("news-image-width"),
                DefaultCity: page.getAttribute("news-default-city"),
                LanguageId: page.getAttribute("news-language-id"),
                MonthFilterCount: page.getAttribute("news-month-filter-count"),
                PageSize: page.getAttribute("news-page-size"),
                PreviewLength: page.getAttribute("news-preview-length"),
                NewsPageId: page.getAttribute("news-newspage-id")
              };
    
              if (eventProps && newsProps) {
                this.eventRequest.request.Settings = {
                  ...this.eventRequest.request.Settings,
                  ...eventProps
                };
                this.newsRequest.request.Settings = {
                  ...this.newsRequest.request.Settings,
                  ...newsProps
                };
    
                await this.fetchEvents(eventsUrl, this.eventRequest);
                await this.fetchNews(newsUrl, this.newsRequest);
    
                this.combineEventsAndNews();
              }
            }
          }
        },
        combineEventsAndNews() {
          let arr = [...this.events, ...this.news];
          console.log({"arr": arr});
          console.log({"shuffled arr": this.shuffle(arr)});
    
    
          this.formatDateAndFilterByDate(arr);
        },
        async formatDateAndFilterByDate(arr) {
          if (arr) {
            try {
              arr.forEach(element => {
                if (element.NewsPageId) {
                  let momentDate = element.PublishedDate.slice(6, -2);
                  let converMomentToDate = new Date(parseInt(momentDate, 10));
                  let newMomentDate = moment(converMomentToDate)
                    .locale("sv")
                    .format("LL");
                  element.PublishedDate = newMomentDate;
                  element.date = converMomentToDate;
                }
                if (element.CalendarPageId) {
                  let momentDate = element.EventStartDate.slice(6, -2);
                  let converMomentToDate = new Date(parseInt(momentDate, 10));
                  let newMomentDate = moment(converMomentToDate)
                    .locale("sv")
                    .format("LL");
                  element.EventStartDate = newMomentDate;
    
                  let momentDate1 = element.ChangedDate.slice(6, -2);
                  let converMomentToDate1 = new Date(parseInt(momentDate1, 10));
                  let newMomentDate1 = moment(converMomentToDate1)
                    .locale("sv")
                    .format("LL");
                  element.ChangedDate = newMomentDate1;
                  element.date = converMomentToDate1;
                }
              });
              let data = arr;
              data.sort((a, b) => a.date.getTime() - b.date.getTime());
              this.items = data.reverse();
              this.isLoading(false);
            } catch (error) {
              this.isLoading(false);
            }
          }
        },
        async fetchEvents(url, req) {
          try {
            let response = await fetch(url, {
              method: "post",
              headers: {
                Accept: "application/json",
                "Content-Type": "application/json"
              },
              body: JSON.stringify(req)
            });
            let data = await response.json();
            if (data.d) {
              this.events = data.d.Events;
            } else {
              this.events = data.Events;
            }
          } catch (error) {
            this.isLoading(false);
          }
        },
        shuffle(array) {
          var currentIndex = array.length, temporaryValue, randomIndex;
        
          // While there remain elements to shuffle...
          while (0 !== currentIndex) {
        
            // Pick a remaining element...
            randomIndex = Math.floor(Math.random() * currentIndex);
            currentIndex -= 1;
        
            // And swap it with the current element.
            temporaryValue = array[currentIndex];
            array[currentIndex] = array[randomIndex];
            array[randomIndex] = temporaryValue;
          }
        
          return array;
        },
        async fetchNews(url, req) {
          try {
            
            let response = await fetch(url, {
              method: "post",
              headers: {
                Accept: "application/json",
                "Content-Type": "application/json"
              },
              body: JSON.stringify(req)
            });
            let data = await response.json();
    
            if (data.d) {
              this.news = data.d.Events;
            } else {
              this.news = data.Events;
            }
          } catch (error) {
            this.isLoading(false);
          }
        }
      }
    });
    
  • URL: /components/raw/newsandeventsblock/NewsAndEventsBlock.js
  • Filesystem Path: src\components\02-block_components\NewsAndEventsBlock\NewsAndEventsBlock.js
  • Size: 8.2 KB
  • Content:
    .newsandeventsblock {
      article {
        &.fake--article {
          .fake--image {
            width: 100%;
            height: 197px;
          }
          .fake--title {
            width: 75%;
            height: 20px;
          }
          .fake--text {
            div {
              width: 75%;
              height: 10px;
              margin-bottom: 10px;
              &:nth-child(2) {
                width: 55%;
              }
              &:nth-child(3) {
                width: 35%;
              }
            }
          }
        }
        //margin-bottom: $md-space;
        margin-bottom: 50px;
        .article--image {
          margin-bottom: $xs-space;
          background-position: center;
          background-repeat: no-repeat;
          background-size: cover;
          height: 197px;
          position: relative;
          width: 100%;
          &:hover {
            .caption {
              text-decoration: none;
            }
          }
          .caption {
            position: absolute;
            left: 0;
            bottom: 0;
            font-size: 16px;
            margin-bottom: 0px;
          }
        }
      }
    }
    
    .loading-container {
      height: 100px;
      padding: 10px;
    }
    .loading {
      animation-duration: 1s;
      animation-fill-mode: forwards;
      animation-iteration-count: infinite;
      animation-name: wave;
      animation-timing-function: linear;
      -webkit-animation-duration: 1s;
      -webkit-animation-fill-mode: forwards;
      -webkit-animation-iteration-count: infinite;
      -webkit-animation-name: wave;
      -webkit-animation-timing-function: linear;
      -moz-animation-duration: 1s;
      -moz-animation-fill-mode: forwards;
      -moz-animation-iteration-count: infinite;
      -moz-animation-name: wave;
      -moz-animation-timing-function: linear;
      background: $bg-grey;
      background-image: -webkit-gradient(
        linear,
        left center,
        right center,
        from($bg-grey),
        color-stop(0.2, #fff),
        color-stop(0.4, #fff),
        to($bg-grey)
      );
      background-image: -webkit-linear-gradient(
        left,
        $bg-grey 0%,
        #fff 20%,
        #fff 40%,
        $bg-grey 100%
      );
      background-image: -moz-gradient(
        linear,
        left center,
        right center,
        from($bg-grey),
        color-stop(0.2, #fff),
        color-stop(0.4, #fff),
        to($bg-grey)
      );
      background-image: -moz-linear-gradient(
        left,
        $bg-grey 0%,
        #fff 20%,
        #fff 40%,
        $bg-grey 100%
      );
      background-repeat: no-repeat;
      background-size: cover;
      height: 104px;
      position: relative;
    }
    .reverse-direction .loading {
      -webkit-animation-direction: reverse;
      -moz-animation-direction: reverse;
    }
    
    @-webkit-keyframes wave {
      0% {
        background-position: -468px 0;
      }
      100% {
        background-position: 468px 0;
      }
    }
    @-moz-keyframes wave {
      0% {
        background-position: -468px 0;
      }
      100% {
        background-position: 468px 0;
      }
    }
    
  • URL: /components/raw/newsandeventsblock/NewsAndEventsBlock.scss
  • Filesystem Path: src\components\02-block_components\NewsAndEventsBlock\NewsAndEventsBlock.scss
  • Size: 2.8 KB

There are no notes for this item.