_createProject() {
    const projectName = this.shadowRoot.getElementById("input-project-name").value;
    const linkedGroupName = this.shadowRoot.getElementById("input-group-name").value;
    const linkedGroup = this.groups.find(group => group.name == linkedGroupName);

    // close dialog (then also the button is not clickable and user cannot create project twice or more often)
    // important: get projectName before closing dialog, because when closing the dialog the input field gets cleared
    this._closeCreateProjectDialogClicked();

    // show loading dialog
    this.shadowRoot.getElementById("dialog-loading").open();

    // currently fetches members from contact service but does not check whether project already exists (code is there but commented)
    if(projectName) {
      fetch(this.contactServiceURL + "/groups/" + linkedGroupName + "/member", {
        method: "GET",
        headers: Auth.getAuthHeaderWithSub() 
      }).then( response => {
          if(!response.ok) throw Error(response.status);
          console.log(typeof response)
          console.log("ssssssss" + Object.keys(response));
          return response.json();
      }).then(data => {
        console.log(data);
        const users = Object.values(data);
        const body = {
          "name": projectName,
          "access_token": Auth.getAccessToken(),
          "linkedGroup": linkedGroup,
          "users": users
        };
        if(GitHub.gitHubUsernameStored()) {
          body.gitHubUsername = GitHub.getGitHubUsername();
        }
        //const newProject = {"id":this.projects.length, "name":projectName, "Linked Group":linkedGroup, "Group Members":users};
          fetch(this.projectServiceURL + "/projects/" + this.system, {
          method: "POST",
          headers:  Auth.getAuthHeaderWithSub(),
          body: JSON.stringify(body)
        }).then(response => {
          console.log(response);
          // close loading dialog
          this.shadowRoot.getElementById("dialog-loading").close();

          if(response.status == 201) {
            // project got created successfully
            this.shadowRoot.getElementById("toast-success").show();

            // clear input field for project name in the dialog
            this.shadowRoot.getElementById("input-project-name").value = "";

            // since a new project exists, reload projects from server
            this.showProjects(false);
            // switch to tab "My Projects"
            this.tabSelected = 0;
            this.shadowRoot.getElementById("my-and-all-projects").selected = 0;
          } else if(response.status == 409) {
            // a project with the given name already exists
            this.shadowRoot.getElementById("toast-already-existing").show();
          } else if(response.status == 401) {
            Auth.removeAuthDataFromLocalStorage();
       //     location.reload();
          }
          // TODO: check what happens when access_token is missing in localStorage
        });
      });
    }
  }
/**
   * Get called when the user click on "create" in the create project dialog.
   */
Get called when the user click on "create" in the create project dialog.
Get called when the user click on " create " in the create project dialog .
_createProject() {
    const projectName = this.shadowRoot.getElementById("input-project-name").value;
    const linkedGroupName = this.shadowRoot.getElementById("input-group-name").value;
    const linkedGroup = this.groups.find(group => group.name == linkedGroupName);
    this._closeCreateProjectDialogClicked();
    this.shadowRoot.getElementById("dialog-loading").open();
    if(projectName) {
      fetch(this.contactServiceURL + "/groups/" + linkedGroupName + "/member", {
        method: "GET",
        headers: Auth.getAuthHeaderWithSub() 
      }).then( response => {
          if(!response.ok) throw Error(response.status);
          console.log(typeof response)
          console.log("ssssssss" + Object.keys(response));
          return response.json();
      }).then(data => {
        console.log(data);
        const users = Object.values(data);
        const body = {
          "name": projectName,
          "access_token": Auth.getAccessToken(),
          "linkedGroup": linkedGroup,
          "users": users
        };
        if(GitHub.gitHubUsernameStored()) {
          body.gitHubUsername = GitHub.getGitHubUsername();
        }
          fetch(this.projectServiceURL + "/projects/" + this.system, {
          method: "POST",
          headers:  Auth.getAuthHeaderWithSub(),
          body: JSON.stringify(body)
        }).then(response => {
          console.log(response);
          this.shadowRoot.getElementById("dialog-loading").close();
          if(response.status == 201) {
            this.shadowRoot.getElementById("toast-success").show();
            this.shadowRoot.getElementById("input-project-name").value = "";
            this.showProjects(false);
            this.tabSelected = 0;
            this.shadowRoot.getElementById("my-and-all-projects").selected = 0;
          } else if(response.status == 409) {
            this.shadowRoot.getElementById("toast-already-existing").show();
          } else if(response.status == 401) {
            Auth.removeAuthDataFromLocalStorage();
          }
        });
      });
    }
  }
_createProject ( ) { const projectName = this . shadowRoot . getElementById ( "input-project-name" ) . value ; const linkedGroupName = this . shadowRoot . getElementById ( "input-group-name" ) . value ; const linkedGroup = this . groups . find ( group => group . name == linkedGroupName ) ; this . _closeCreateProjectDialogClicked ( ) ; this . shadowRoot . getElementById ( "dialog-loading" ) . open ( ) ; if ( projectName ) { fetch ( this . contactServiceURL + "/groups/" + linkedGroupName + "/member" , { method : "GET" , headers : Auth . getAuthHeaderWithSub ( ) } ) . then ( response => { if ( ! response . ok ) throw Error ( response . status ) ; console . log ( typeof response ) console . log ( "ssssssss" + Object . keys ( response ) ) ; return response . json ( ) ; } ) . then ( data => { console . log ( data ) ; const users = Object . values ( data ) ; const body = { "name" : projectName , "access_token" : Auth . getAccessToken ( ) , "linkedGroup" : linkedGroup , "users" : users } ; if ( GitHub . gitHubUsernameStored ( ) ) { body . gitHubUsername = GitHub . getGitHubUsername ( ) ; } fetch ( this . projectServiceURL + "/projects/" + this . system , { method : "POST" , headers : Auth . getAuthHeaderWithSub ( ) , body : JSON . stringify ( body ) } ) . then ( response => { console . log ( response ) ; this . shadowRoot . getElementById ( "dialog-loading" ) . close ( ) ; if ( response . status == 201 ) { this . shadowRoot . getElementById ( "toast-success" ) . show ( ) ; this . shadowRoot . getElementById ( "input-project-name" ) . value = "" ; this . showProjects ( false ) ; this . tabSelected = 0 ; this . shadowRoot . getElementById ( "my-and-all-projects" ) . selected = 0 ; } else if ( response . status == 409 ) { this . shadowRoot . getElementById ( "toast-already-existing" ) . show ( ) ; } else if ( response . status == 401 ) { Auth . removeAuthDataFromLocalStorage ( ) ; } } ) ; } ) ; } }
Get called when the user click on "create" in the create project dialog.
Get called when the user click on " create " in the create project dialog .
// close dialog (then also the button is not clickable and user cannot create project twice or more often) // important: get projectName before closing dialog, because when closing the dialog the input field gets cleared // show loading dialog // currently fetches members from contact service but does not check whether project already exists (code is there but commented) //const newProject = {"id":this.projects.length, "name":projectName, "Linked Group":linkedGroup, "Group Members":users}; // close loading dialog // project got created successfully // clear input field for project name in the dialog // since a new project exists, reload projects from server // switch to tab "My Projects" // a project with the given name already exists //     location.reload(); // TODO: check what happens when access_token is missing in localStorage