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

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
15
16
17
18
19
20
21
22
23
24
25
26
27
  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
28
29
        });
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
30
31
32
33
34
35
36
37
38
39
40
41
42

      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
43
44
  })

Rosanny Sihombing's avatar
Rosanny Sihombing committed
45
46
47
48
49
50
51
52
53
54
  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
55

Rosanny Sihombing's avatar
Rosanny Sihombing committed
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
      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
73
74
75
76
77
78
79
  })

  // Projektdaten
  app.get('/projektdaten', async function(req:any, res:any){
    let projectArr = []
    let isProject = true
    let firstId = 0
Rosanny Sihombing's avatar
Rosanny Sihombing committed
80
    let orderKeyword = req.query.sort
Rosanny Sihombing's avatar
Rosanny Sihombing committed
81
82
83
84
85
86
87
88
89
90
91
92

    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) {
Athanasios's avatar
Athanasios committed
93
            projectData[i].avatar_url = "https://m4lab.hft-stuttgart.de/img/body/M4_LAB_LOGO_NO_TEXT.png"
Rosanny Sihombing's avatar
Rosanny Sihombing committed
94
95
96
97
98
99
100
101
102
103
104
          }
          // 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,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
105
106
107
            keywords: projectData[i].tag_list,
            createdAt: projectData[i].created_at,
            lastUpdatedAt: projectData[i].last_activity_at
Rosanny Sihombing's avatar
Rosanny Sihombing committed
108
109
110
111
112
          }
          projectArr.push(project)
        }
        firstId = projectData[projectData.length-1].id
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136

      // MLAB-576
      if (orderKeyword == "created_at") {
        projectArr.sort((a, b) => {
          let aDate:any = new Date(a.createdAt)
          let bDate:any = new Date(b.createdAt)
          return bDate - aDate
        });
      } else if (orderKeyword == "updated_at") {
        projectArr.sort((a, b) => {
          let aDate:any = new Date(a.lastUpdatedAt)
          let bDate:any = new Date(b.lastUpdatedAt)
          return bDate - aDate
        });
      } else { // default, sorted by name
        projectArr.sort((a, b) => {
          let fa = a.name.toLowerCase(),
              fb = b.name.toLowerCase();
      
          if (fa < fb) return -1;
          if (fa > fb) return 1;
          return 0;
        });
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
137
138
139
140
141
142
143
144
145
    }

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

  // Projektinformationen
  app.get('/projektinformationen', async function(req:any, res:any){
146
    let pagesArr: { logo: any; name: any; weburl: any; desc: any; keywords: any; createdAt: any; lastUpdatedAt: any; }[] = []
Rosanny Sihombing's avatar
Rosanny Sihombing committed
147
148
    let isProject = true
    let firstId = 0
Rosanny Sihombing's avatar
Rosanny Sihombing committed
149
    let orderKeyword = req.query.sort
Rosanny Sihombing's avatar
Rosanny Sihombing committed
150
151
152
153
154
155
156
157
158
159
160
161
162

    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) {
Athanasios's avatar
Athanasios committed
163
              pagesData[i].avatar_url = "https://m4lab.hft-stuttgart.de/img/body/M4_LAB_LOGO_NO_TEXT.png"
Rosanny Sihombing's avatar
Rosanny Sihombing committed
164
165
166
167
168
            }
            // for all projects that have no description
            if (pagesData[i].description == "") {
              pagesData[i].description = "- no description -"
            }
169
170
            // https://transfer.hft-stuttgart.de/pages/EIGENTUEMER/PROJEKTNAME/
            pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/"+pagesData[i].namespace.path+"/"+pagesData[i].name+"/"
Rosanny Sihombing's avatar
Rosanny Sihombing committed
171
172
173
174
175
176
177
178
179
180
181
182
            // 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,
Rosanny Sihombing's avatar
Rosanny Sihombing committed
183
184
185
              keywords: pagesData[i].tag_list,
              createdAt: pagesData[i].created_at,
              lastUpdatedAt: pagesData[i].last_activity_at
Rosanny Sihombing's avatar
Rosanny Sihombing committed
186
            }
187
188
189
190
191
192

            https.get(pagesData[i].web_url, function (response:any) {
              if (response.statusCode >= 200 && response.statusCode <= 299) {
                pagesArr.push(pages)
              }
            })
Rosanny Sihombing's avatar
Rosanny Sihombing committed
193
194
195
196
          }
        }
        firstId = pagesData[pagesData.length-1].id
      }
Rosanny Sihombing's avatar
Rosanny Sihombing committed
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221

      // MLAB-576
      if (orderKeyword == "created_at") {
        pagesArr.sort((a, b) => {
          let aDate:any = new Date(a.createdAt)
          let bDate:any = new Date(b.createdAt)
          return bDate - aDate
        });
      } else if (orderKeyword == "updated_at") {
        pagesArr.sort((a, b) => {
          let aDate:any = new Date(a.lastUpdatedAt)
          let bDate:any = new Date(b.lastUpdatedAt)
          return bDate - aDate
        });
      } else { // default, sorted by name
        pagesArr.sort((a, b) => {
          let fa = a.name.toLowerCase(),
              fb = b.name.toLowerCase();
      
          if (fa < fb) return -1;
          if (fa > fb) return 1;
          return 0;
        });
      }

Rosanny Sihombing's avatar
Rosanny Sihombing committed
222
223
224
225
226
227
228
229
    }

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

};