import {Component} from '@angular/core';
import {Breadcrumb} from "../../openaireLibrary/utils/breadcrumbs/breadcrumbs.component";
import {EnvProperties} from "../../openaireLibrary/utils/properties/env-properties";
import {ActivatedRoute, Router} from "@angular/router";
import {Meta, Title} from "@angular/platform-browser";
import {SEOService} from "../../openaireLibrary/sharedComponents/SEO/SEO.service";
import {PiwikService} from "../../openaireLibrary/utils/piwik/piwik.service";
import {HelperService} from "../../openaireLibrary/utils/helper/helper.service";
import {Subscriber} from "rxjs";
import {properties} from "../../../environments/environment";

@Component({
  selector: 'faqs',
  template: `
    <schema2jsonld *ngIf="url" [URL]="url" [name]="pageTitle" type="other"></schema2jsonld>
    <div class="uk-container uk-container-large uk-section uk-section-small uk-padding-remove-bottom">
      <div class="uk-padding-small uk-padding-remove-horizontal">
        <breadcrumbs [breadcrumbs]="breadcrumbs"></breadcrumbs>
      </div>
    </div>
    <div class="uk-section uk-padding-remove-top">
      <div class="uk-container uk-container-large uk-margin-top">
        <h1>Frequently Asked Questions</h1>
        <div class="uk-container uk-margin-large-top">
          <ul class="uk-accordion" uk-accordion="">
          <li>
            <a class="uk-accordion-title" href="#">What is a &quot;Research community&quot;?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>A research community is a community of practice that gathers together researchers and practitioners
                with common research interests (e.g. a research discipline or a specific research topic) and,
                possibly, a decisional board. In some cases, a community builds and grows in the context of a research
                infrastructure that provides services and tools supporting the research activities of the members of a
                community. In other cases, a community builds and grows in the context of one or more research
                projects, forming what we call a &ldquo;research initiative&rdquo;.</p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">What is the difference between a Community Gateway and the
              Research Community Dashboard (RCD)?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>The RCD offers on demand Community Gateways that communities can customize to fit their sharing,
                publishing and discovery needs. Through the RCD, gateway managers can configure the respective
                Community Gateway by providing (i) the criteria identifying the subset of the OpenAIRE Research Graph
                that pertains to the community, and (ii) the community statistics to be made public or private.</p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">How can Research Community thematic services integrate with
              the Research Community Dashboard (RCD)?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>Once a Community Gateway has been created, several thematic service integration patterns are
                possible:</p>
              <ol>
                <li>
                  <span class="uk-text-bold">Community-specific repository:</span> OpenAIRE can guide your
                  repository managers on how to make the repository
                  <a href="https://www.openaire.eu/validator-registration-guide" target="_blank"> &ldquo;OpenAIRE-compliant&rdquo;</a>.
                  The gateway managers can configure the gateway so that all metadata records collected from the
                  repository are available in the gateway. If the repository manager wants to get the enrichments
                  OpenAIRE applies to the records, he/she can <a href="https://www.openaire.eu/content-enrichment-guide"
                                                                 target="_blank">
                  activate the Broker service</a> using <a href="https://provide.openaire.eu/landing" target="_blank">the
                  Content
                  Provider Dashboard</a>.
                </li>
                <li>
                  <span class="uk-text-bold">Continuous publishing:</span> thematic services, once authorized by the
                  user, can publish their outputs (e.g. datasets, digital experiments) on behalf of the user. Thematic
                  services and digital experiment platforms can be easily enhanced with a publishing step by
                  integrating the <a href="https://developers.zenodo.org/" target="_blank">Zenodo API</a>. To know
                  more, <a class="uk-link" href="https://doi.org/10.5281/zenodo.1314672" target="_blank"> check out
                  the pilot we have designed with the EPOS-IT infrastructure. </a></li>
                <li>
                  <span class="uk-text-bold">Community web site:</span> you can use the
                  <a href="http://develop.openaire.eu/api.html" target="_blank">OpenAIRE Search API</a> to show the
                  research products relevant to your community on your own website.
                </li>
              </ol>
            </div>
          </li>
          <li><a class="uk-accordion-title" href="#">What does my Research Community gain in terms of Open
            Science?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-grid uk-margin-medium-bottom" hidden="" uk-grid="">
              <div class="uk-width-1-1 uk-first-column"><span
                  class="uk-text-bold">Discovery and reproducibility:</span> Your community will have a single entry
                point where all research products, of any type (literature, datasets, software, workflows, protocols),
                are gathered together and linked with semantic relationships. Researchers can find a research product
                in the gateway (e.g. a research dataset) and easily find out everything related to it and that is
                needed to re-use it, but also to replicate and reproduce a research activity (e.g. software used to
                process the dataset, the journal article where the research is described).
              </div>
              <div class="uk-width-1-1 uk-grid-margin uk-first-column"><span class="uk-text-bold">Sharing:</span>
                scientific literature is only the tip of the iceberg. With a Community Gateway, you say to the members
                of your community that everything they produce is relevant and that they should get credit for it.
              </div>
              <div class="uk-width-1-1 uk-grid-margin uk-first-column"><span
                  class="uk-text-bold">Credit for all:</span> Making research data, software, methods and scientific
                workflows available &ldquo;as soon as possible&rdquo; is one of the &ldquo;mantra&rdquo; of Open
                Science. If your community has integrated Zenodo into a digital experiment platform, researchers no
                longer bear the burden of manually publishing their research products, while it is also easier for
                them to publish different versions, which reflect different stages of their activities.
              </div>
              <div class="uk-width-1-1 uk-grid-margin uk-first-column"><span class="uk-text-bold">Awareness:</span>
                Thanks to dedicated pages of the Community Gateway you can suggest best practices to the researchers
                of the community. Open Science experts of OpenAIRE will be available to assist you.
              </div>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">How is the service part of the European Open Science Cloud?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>OpenAIRE has onboarded in the EOSC Market Place both the RCD, as a service that offers on-demand
                Community Gateways, and the Gateways as services openly accessible by researchers to explore specific
                domains of interest.
              </p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">Who owns the gateway?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>The community owns the portal, OpenAIRE operates it.</p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">How is the gateway operated?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>The gateway is hosted on a virtual machine operated by OpenAIRE and hosted at the <a
                  href="https://icm.edu.pl/en/centre-of-technology/" target="_blank">ICM data centre</a>. The Gateway
                is built with Angular and uses RESTful APIs, built with Java and the Spring Framework, to access the
                OpenAIRE Research Graph. OpenAIRE is responsible to keep the back-end and front-end services
                up-to-date and monitors the uptime and usage of the gateway, via the matomo web analytics platform.
                Aggregated usage data is used by the OpenAIRE team for reporting purposes and does not include any
                personal data.
              </p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">What is the SLA of the service?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <p>The RCD and the gateways are subject to the generic <a class="uk-link"
                                                                        href="https://www.openaire.eu/service-level-agreement"
                                                                        target="_blank">OpenAIRE services SLA</a>.
              </p>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">What are the costs?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-margin-medium-bottom" hidden="">
              <div>Researchers of the community shall not pay to access the Community Gateway.</div>
              <div>For the deployment and maintenance of a gateway, OpenAIRE may need support to cover part of the
                costs (hardware, hardware management, application administration, software maintenance, and text
                mining).
              </div>
              <div>Please <a routerLink="/contact-us">contact us</a> to learn more about the service and the possible
                options.
              </div>
            </div>
          </li>
          <li>
            <a class="uk-accordion-title" href="#">In what other areas can my Research community collaborate with
              OpenAIRE?</a>
            <div aria-hidden="true" class="uk-accordion-content text-small uk-grid uk-margin-medium-bottom" hidden="" uk-grid="">
              <div class="uk-width-1-1">
                <div style="font-style: italic">Open Science training</div>
                Help us training on Open Science students and researchers of your community by organising a workshop.
                <a class="uk-link" href="https://www.openaire.eu/workshops-page" target="_blank">Check for ideas and
                  materials</a>.
              </div>
              <div class="uk-width-1-1">
                <div style="font-style: italic">Train the trainer</div>
                Join the <a class="uk-link" href="https://www.openaire.eu/cop-training" target="_blank">OpenAIRE
                Community of Practice</a>, an informal network to share training experience on Open Science, research
                and e-infrastructures.
              </div>
              <div class="uk-width-1-1">
                <div style="font-style: italic">Citizen Science</div>
                Do you collaborate with schools? Learn more about the
                <a class="uk-link" href="https://www.openaire.eu/citizen-science-activities-in-openaire"
                   target="_blank">
                  OpenAIRE activities for Citizen Science
                </a>.
              </div>
              <div class="uk-width-1-1">
                <div style="font-style: italic">Open Innovation Programme</div>
                Spread the word about the OpenAIRE
                <a class="uk-link" href="https://www.openaire.eu/open-innovation-in-openaire" target="_blank">Open
                  Innovation programme</a>
                for SMEs, start-ups and research labs. The programme&rsquo;s goal is to discover, support and fund
                innovative
                ideas and implementations of software in the Open Science domain.
              </div>
            </div>
          </li>
        </ul>
        </div>
      </div>
    </div>
  `
})
export class FaqsComponent {
  public pageTitle: string = "OpenAIRE - Connect | FAQs";
  public pageDescription: string = "Frequently asked questions about OpenAIRE Connect research gateway";
  public breadcrumbs: Breadcrumb[] = [{name: 'home', route: '/'}, {name: 'About', route: '/about'}, {name: 'FAQs'}];
  private subscriptions = [];
  public pageContents = null;
  public divContents = null;
  public url: string = null;
  properties: EnvProperties;
  
  constructor(
    private route: ActivatedRoute,
    private _router: Router,
    private _meta: Meta,
    private _title: Title,
    private seoService: SEOService,
    private _piwikService: PiwikService,
    private helper: HelperService) {
  }
  
  public ngOnInit() {

        this.properties = properties;
        this.subscriptions.push(this._piwikService.trackView(this.properties, this.pageTitle).subscribe());
        this.url = this.properties.baseLink + this._router.url;
        this.seoService.createLinkForCanonicalURL(this.url);
        this.updateUrl(this.url);
        this.updateTitle(this.pageTitle);
        this.updateDescription(this.pageDescription);
        
        //this.getDivContents();
        this.getPageContents();

  }
  
  private getPageContents() {
    this.subscriptions.push(this.helper.getPageHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
      this.pageContents = contents;
    }));
  }
  
  private getDivContents() {
    this.subscriptions.push(this.helper.getDivHelpContents(this.properties, 'connect', this._router.url).subscribe(contents => {
      this.divContents = contents;
    }));
  }

  ngOnDestroy() {
    this.subscriptions.forEach(subscription => {
      if (subscription instanceof Subscriber) {
        subscription.unsubscribe();
      }
    });
  }
  
  private updateDescription(description: string) {
    this._meta.updateTag({content: description}, "name='description'");
    this._meta.updateTag({content: description}, "property='og:description'");
  }
  
  private updateTitle(title: string) {
    var _title = ((title.length > 50) ? title.substring(0, 50) : title);
    this._title.setTitle(_title);
    this._meta.updateTag({content: _title}, "property='og:title'");
  }
  
  private updateUrl(url: string) {
    this._meta.updateTag({content: url}, "property='og:url'");
  }
}
