showProjects(allProjects) {
    // set loading to true
    this.projectsLoading = true;
    // clear current project list
    this.projects = [];
    this.listedProjects = [];

    if(!Auth.userInfoAvailable()) {
        // user is not logged in (cannot load projects)
        this.projectsLoading = false;
        return;
    }

    fetch(this.projectServiceURL + "/projects/" + this.system, {
      method: "GET",
      headers: Auth.getAuthHeaderWithSub()
    }).then(response => {
      if(!response.ok) throw Error(response.status);
      return response.json();
    }).then(data => {
      console.log("Projects are", data.projects);
      // set loading to false, then the spinner gets hidden
      this.projectsLoading = false;

      // send event (containing every project, not only the ones from the user)
      let event = new CustomEvent("projects-loaded", {
        detail: {
          projects: data.projects
        },
        bubbles: true
      });
      this.dispatchEvent(event);


      // if we only want to show the projects, where the user is a member of, we need to filter out some projects
      if(!allProjects) data.projects = data.projects.filter(project => project.is_member);

      // store loaded projects
      this.projects = data.projects;
      // set projects that should be shown (currently all)
      this.listedProjects = data.projects;
    }).catch(error => {
      if(error.message == "401") {
        // user is not authorized
        // maybe the access token has expired
        Auth.removeAuthDataFromLocalStorage();
        //   location.reload();
      } else {
        console.log(error);
      }
    });
  }
/**
   * Loads and shows the projects that the user is a member of, or all existing projects.
   * @param allProjects If all projects should be shown or only the ones where the
   * current user is a member of.
   */
Loads and shows the projects that the user is a member of, or all existing projects.
@param allProjects If all projects should be shown or only the ones where the
current user is a member of.
Loads and shows the projects that the user is a member of or all existing projects . @param allProjects If all projects should be shown or only the ones where the current user is a member of .
showProjects(allProjects) {
    this.projectsLoading = true;
    this.projects = [];
    this.listedProjects = [];
    if(!Auth.userInfoAvailable()) {
        this.projectsLoading = false;
        return;
    }
    fetch(this.projectServiceURL + "/projects/" + this.system, {
      method: "GET",
      headers: Auth.getAuthHeaderWithSub()
    }).then(response => {
      if(!response.ok) throw Error(response.status);
      return response.json();
    }).then(data => {
      console.log("Projects are", data.projects);
      this.projectsLoading = false;
      let event = new CustomEvent("projects-loaded", {
        detail: {
          projects: data.projects
        },
        bubbles: true
      });
      this.dispatchEvent(event);
      if(!allProjects) data.projects = data.projects.filter(project => project.is_member);
      this.projects = data.projects;
      this.listedProjects = data.projects;
    }).catch(error => {
      if(error.message == "401") {
        Auth.removeAuthDataFromLocalStorage();
      } else {
        console.log(error);
      }
    });
  }
showProjects ( allProjects ) { this . projectsLoading = true ; this . projects = [ ] ; this . listedProjects = [ ] ; if ( ! Auth . userInfoAvailable ( ) ) { this . projectsLoading = false ; return ; } fetch ( this . projectServiceURL + "/projects/" + this . system , { method : "GET" , headers : Auth . getAuthHeaderWithSub ( ) } ) . then ( response => { if ( ! response . ok ) throw Error ( response . status ) ; return response . json ( ) ; } ) . then ( data => { console . log ( "Projects are" , data . projects ) ; this . projectsLoading = false ; let event = new CustomEvent ( "projects-loaded" , { detail : { projects : data . projects } , bubbles : true } ) ; this . dispatchEvent ( event ) ; if ( ! allProjects ) data . projects = data . projects . filter ( project => project . is_member ) ; this . projects = data . projects ; this . listedProjects = data . projects ; } ) . catch ( error => { if ( error . message == "401" ) { Auth . removeAuthDataFromLocalStorage ( ) ; } else { console . log ( error ) ; } } ) ; }
Loads and shows the projects that the user is a member of, or all existing projects.
Loads and shows the projects that the user is a member of or all existing projects .
// set loading to true // clear current project list // user is not logged in (cannot load projects) // set loading to false, then the spinner gets hidden // send event (containing every project, not only the ones from the user) // if we only want to show the projects, where the user is a member of, we need to filter out some projects // store loaded projects // set projects that should be shown (currently all) // user is not authorized // maybe the access token has expired //   location.reload();