project.ts 6.28 KB
Newer Older
Rosanny Sihombing's avatar
Rosanny Sihombing committed
1
2
3
4
5
6
7
8
9
10
11
12
13
//const SamlStrategy = require('passport-saml').Strategy
import methods from '../functions/methods'
import gitlab from '../functions/gitlab'
import helpers from '../functions/helpers'

module.exports = function (app:any, lang:string) {
 
  // ======== APP ROUTES - PROJECT ====================
  
  app.get('/', function (req:any, res:any) {
    res.render(lang+'/project/project-simplified')
  })

Rosanny Sihombing's avatar
Rosanny Sihombing committed
14
15
16
17
18
19
20
21
22
23
24
25
26
  app.get('/mailinglists', async function (req:any, res:any) {
    let mailList = await methods.getAllMailinglists()
    if (mailList) {
      let allMailingLists = []  // JSON object
      for (let i = 0; i < mailList.length; i++) {
        // add data to JSON object
        allMailingLists.push({
          id: mailList[i].id,
          name: mailList[i].name,
          src: mailList[i].src,
          projectstatus: mailList[i].projectstatus,
          project_title: mailList[i].project_title,
          keywords: mailList[i].keywords
Rosanny Sihombing's avatar
Rosanny Sihombing committed
27
28
        });
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
29
30
31
32
33
34
35
36
37
38
39
40
41

      res.render(lang+'/project/mailinglists', {
        //isUserAuthenticated: req.isAuthenticated(),
        //user: req.user,
        mailinglists: allMailingLists
      });
    } else {
      res.render(lang+'/project/mailinglists', {
        //isUserAuthenticated: req.isAuthenticated(),
        //user: req.user,
        mailinglists: null
      })
    }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
42
43
  })

Rosanny Sihombing's avatar
Rosanny Sihombing committed
44
45
46
47
48
49
50
51
52
53
  app.get('/projectoverview', async function(req:any, res:any){
    let projectOverview = await methods.getProjectOverviewById(req.query.projectID)
    if (projectOverview.length > 0) {
      let partnerWebsites = helpers.stringToArray(projectOverview[0].partner_website)
      let partnerNames = helpers.stringToArray(projectOverview[0].partner_name)
      let awardSites = helpers.stringToArray(projectOverview[0].award_website)
      let awardNames = helpers.stringToArray(projectOverview[0].award_name)
      let sponsorWebsites = helpers.stringToArray(projectOverview[0].sponsor_website)
      let sponsorImgs = helpers.stringToArray(projectOverview[0].sponsor_img)
      let sponsorNames = helpers.stringToArray(projectOverview[0].sponsor_name)
Rosanny Sihombing's avatar
Rosanny Sihombing committed
54

Rosanny Sihombing's avatar
Rosanny Sihombing committed
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
      let projectImages = await methods.getProjectImagesById(req.query.projectID)
      res.render(lang+'/project/projectOverview', {
        //isUserAuthenticated: req.isAuthenticated(),
        //user: req.user,
        projectOV: projectOverview,
        projectImgs: projectImages,
        partnerWS: partnerWebsites,
        partnerN: partnerNames,
        awardWS: awardSites,
        awardN: awardNames,
        sponsorWS: sponsorWebsites,
        sponsorIMG: sponsorImgs,
        sponsorN: sponsorNames
      });
    } else {
      res.redirect('/')
    }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
  })

  // Projektdaten
  app.get('/projektdaten', async function(req:any, res:any){
    let projectArr = []
    let isProject = true
    let firstId = 0

    while (isProject == true) {
      let projects = await gitlab.getProjects(100, firstId)
      let projectData = projects.data[0]

      if (projectData.length == 0) {
        isProject = false
      }
      else {
        for(let i = 0; i < projectData.length; i++){
          // M4_LAB logo for all projects that do not have logo
          if (projectData[i].avatar_url == null) {
            projectData[i].avatar_url = "https://m4lab.hft-stuttgart.de/img/footer/M4_LAB_LOGO_Graustufen.png"
          }
          // for all projects that have no description
          if (projectData[i].description == "") {
            projectData[i].description = "- no description -"
          }

          let project = {
            logo: projectData[i].avatar_url,
            name: projectData[i].name,
            weburl: projectData[i].web_url,
            desc: projectData[i].description,
            keywords: projectData[i].tag_list
          }
          projectArr.push(project)
        }
        firstId = projectData[projectData.length-1].id
      }
    }

    res.render(lang+'/project/projectList', {
      project: projectArr
    })
  })

  // Projektinformationen
  app.get('/projektinformationen', async function(req:any, res:any){
    let pagesArr = []
    let isProject = true
    let firstId = 0

    while (isProject == true) {
      let projects = await gitlab.getProjects(100, firstId)
      let pagesData = projects.data[1]

      if (pagesData.length == 0) {
        isProject = false
      } else {
        for(let i = 0; i < pagesData.length; i++){
          let status = await gitlab.getLatestPipelineStatus(pagesData[i].id)
          if (status) {
            // M4_LAB logo for all projects that do not have logo
            if (pagesData[i].avatar_url == null) {
              pagesData[i].avatar_url = "https://m4lab.hft-stuttgart.de/img/footer/M4_LAB_LOGO_Graustufen.png"
            }
            // for all projects that have no description
            if (pagesData[i].description == "") {
              pagesData[i].description = "- no description -"
            }
            // customized website name
            if (pagesData[i].name == "Visualization") {
              //todo: update URL - user? group?
              pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/visualization"
            }
            else if (pagesData[i].name == "IN-Source") {
              //todo: update URL
              pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/INsource"
            }
            else if (pagesData[i].name == "3DS_Visualization_Cesium") {
              //todo: update URL
              pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/3ds_visualization_cesium"
            }
            else {
              //todo: update URL
              pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/"+pagesData[i].name
            }
            // remove 'website' from tag list
            let index = pagesData[i].tag_list.indexOf('website')
            if (index > -1) {
              pagesData[i].tag_list.splice(index, 1)
            }

            // fill in pagesArr
            let pages = {
              logo: pagesData[i].avatar_url,
              name: pagesData[i].name,
              weburl: pagesData[i].web_url,
              desc: pagesData[i].description,
              keywords: pagesData[i].tag_list
            }
            pagesArr.push(pages)
          }
        }
        firstId = pagesData[pagesData.length-1].id
      }
    }

    res.render(lang+'/project/pagesList', {
      pages: pagesArr
    })
  })

};