routes-project.js 4.59 KB
Newer Older
1
2
3
4
5
6
7
8
const methods = require('./methods')
const async = require('async')

module.exports = function (app) {
 
  // ======== APP ROUTES - PROJECT ====================
  var lang = 'DE'

Rosanny Sihombing's avatar
Rosanny Sihombing committed
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
  app.get('/mailinglists', function (req, res) {
    async.waterfall([
        function(done) {
            methods.getAllMailinglists(function(mailinglistOverview, err) {
                if (!err) {
                    done(err, mailinglistOverview)
                }
            })
        },
        // create JSON object of mailinglists for front-end
        function(mailinglistOverview, done) {
            var allMailingLists = []  // JSON object
            for (let i = 0; i < mailinglistOverview.length; i++) {
                // add data to JSON object
                allMailingLists.push({
                    id: mailinglistOverview[i].id,
                    name: mailinglistOverview[i].name,
                    src: mailinglistOverview[i].src,
                    projectstatus: mailinglistOverview[i].projectstatus,
                    project_title: mailinglistOverview[i].project_title
                });
            }

            res.render(lang+'/project/mailinglists', {
                isUserAuthenticated: req.isAuthenticated(),
                user: req.user,
                mailinglists: allMailingLists
            });
        }
    ])
  });

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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
  app.get('/project', function (req, res) {
    async.waterfall([
      // get all projects from projectdb
      function(done) {
        methods.getAllProjects(function(projectsOverview, err) {
          if (!err) {
            done(err, projectsOverview)
          }
        })
      },
      // create JSON object for front-end
      function(projectsOverview, done) {
        var activeProjects = []
        var nonActiveProjects = []

        for (var i = 0; i < projectsOverview.length; i++) {
          var project = {
            id: projectsOverview[i].id,
            logo: projectsOverview[i].logo,
            akronym: projectsOverview[i].pname,
            title: projectsOverview[i].title,
            summary: projectsOverview[i].onelinesummary,
            category: projectsOverview[i].category,
            cp: projectsOverview[i].contact_email,
            gitlab: projectsOverview[i].gitlab
          }
          if (projectsOverview[i].projectstatus == 0) {
            nonActiveProjects.push(project)
          }
          else if (projectsOverview[i].projectstatus == 1) {
            activeProjects.push(project)
          }
        }

        // render the page
        if (req.isAuthenticated()) {
          res.render(lang+'/project/projects', {
            isUserAuthenticated: true,
            nonActive: nonActiveProjects,
            active: activeProjects
          });
        }
        else {
          res.render(lang+'/project/projects', {
            isUserAuthenticated: false,
            nonActive: nonActiveProjects,
            active: activeProjects
          });
        }
      }
    ])
  })

  app.get('/addprojectoverview', function (req, res) {
    if (req.isAuthenticated()) {
      res.render(lang+'/project/addProjectOverview')
    }
    else {
      res.redirect('/login')
    }
  })
  
  app.post('/addprojectoverview', function (req, res) {
    if (req.isAuthenticated()) {
      var wiki = 0
      if (req.body.wiki)
        wiki = 1

      var projectOverviewData = {
        pname: req.body.pname,
        title: req.body.title,
        onelinesummary: req.body.summary,
        category: req.body.category,
        logo: req.body.logo,
        gitlab: req.body.gitlabURL,
        wiki: wiki,
        overview: req.body.overview,
        question: req.body.question,
        approach: req.body.approach,
        result: req.body.result,
        keywords: req.body.keywords,
        announcement: req.body.announcement,
        term: req.body.term,
        further_details: req.body.furtherDetails,
        website: req.body.website,
        src: req.body.src,
        caption: req.body.caption,
        contact_firstname: req.body.contactFirstname,
        contact_lastname: req.body.contactLastname,
        contact_email: req.body.contactEmail,
        leader_firstname: req.body.leaderFirstname,
        leader_lastname: req.body.leaderLastname,
        leader_email: req.body.leaderEmail
      }
      
      methods.addProjectOverview(projectOverviewData, function(err){
        if (err) {
          //req.flash('error', "Failed")
          req.flash('error', "Fehlgeschlagen")
          res.redirect('/addProjectOverview');
        }
        else {
          req.flash('success', 'Your project has been created.')
          res.redirect('/project');
        }
      })
    }
  })
  
};