Commit ad044c97 authored by Varun Srivastava's avatar Varun Srivastava
Browse files

Merge branch 'testing' into 'development_varun'

Testing

See merge request !34
parents a9ea21c0 8706e273
......@@ -55,12 +55,10 @@ app.use(function(req, res, next) {
next()
})
//require('./routes/routes-account')(app, config, passport, i18n);
require('./routes/routes-project')(app, config, passport)
// Handle 404
app.use(function (req, res, next) {
//res.status(404).send('404: Page not Found', 404)
res.status(404).render('./DE/404')
})
......
......@@ -29,6 +29,9 @@ module.exports = {
authPass: 'passwordmail',
tlsCiphers: 'SSLv3',
from: 'email_from',
},
gitlab: {
token_readWriteProjects: 'putyourtokenhere'
}
},
testing: {
......@@ -61,6 +64,9 @@ module.exports = {
authPass: 'passwordmail',
tlsCiphers: 'SSLv3',
from: 'email_from',
},
gitlab: {
token_readWriteProjects: 'putyourtokenhere'
}
},
production: {
......
This diff is collapsed.
......@@ -7,8 +7,7 @@
"email": "rosanny.sihombing@hft-stuttgart.de"
},
"keywords": [
"m4_lab",
"prjects"
"m4_lab"
],
"repository": {
"type": "git",
......@@ -20,7 +19,7 @@
},
"dependencies": {
"async": "^3.2.0",
"axios": "^0.20.0",
"axios": "^0.21.1",
"body-parser": "^1.19.0",
"compression": "^1.7.4",
"cookie-parser": "1.4.3",
......@@ -34,8 +33,8 @@
"morgan": "^1.10.0",
"mysql": "^2.18.1",
"passport": "0.3.2",
"passport-saml": "^1.3.4",
"pug": "^2.0.4"
"passport-saml": "^2.0.6",
"pug": "^3.0.2"
},
"engines": {
"node": ">= 4.0.0"
......
const axios = require('axios')
var gitlab = {
getProjects: async function(perPage, idAfter) {
try {
let projects = await axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects?visibility=public&pagination=keyset&per_page='+perPage+'&order_by=id&sort=asc&id_after='+idAfter
})
let data = projects.data
let reposArr = []
let pagesArr = []
for(let i = 0; i < data.length; i++){
// skip template project
if (data[i].name == 'page_basic' || data[i].name == 'generic' || data[i].name == 'simple_raw' || data[i].name == 'simple_thesis') {
continue
} else if(data[i].tag_list.includes('website')) {
pagesArr.push(data[i])
} else {
reposArr.push(data[i])
}
}
return {
error: false,
data: [reposArr, pagesArr]}
}
catch (err) {
return {
error: true,
data: err}
}
},
getLatestPipelineStatus: async function(projectId) {
return axios({
method: 'get',
url: 'https://transfer.hft-stuttgart.de/gitlab/api/v4/projects/'+projectId+'/pipelines'
})
.then(res => res.data[0].status)
.catch(err => console.error(err))
}
}
module.exports = gitlab
\ No newline at end of file
const fs = require('fs')
//const SamlStrategy = require('passport-saml').Strategy
const dbconn = require('./dbconn')
const methods = require('./methods')
const gitlab = require('./gitlab')
// pwd encryption
//const bcrypt = require('bcryptjs');
//const saltRounds = 10;
......@@ -10,10 +9,8 @@ const methods = require('./methods')
const async = require('async')
//const crypto = require('crypto')
//const mailer = require('./mailer')
const helpers = require('./helpers')
const pictSizeLimit = 1000000 // 1 MB
const axios = require('axios')
module.exports = function (app) {
......@@ -53,59 +50,6 @@ module.exports = function (app) {
])
})
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('/', function (req, res) {
res.render(lang+'/project/project-simplified', {
isUserAuthenticated: req.isAuthenticated(),
......@@ -121,52 +65,6 @@ module.exports = function (app) {
res.redirect('/login')
}
})
app.post('/addprojectoverview__', function (req, res) {
if (req.isAuthenticated()) {
var wiki = 0
if (req.body.wiki)
wiki = 1
var projectTerm = req.body.termForm + " - " + req.body.termTo
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: projectTerm,
further_details: req.body.furtherDetails,
website: req.body.website,
src: req.body.src,
caption: req.body.caption,
contact_lastname: req.body.contactName,
contact_email: req.body.contactEmail,
leader_lastname: req.body.leaderName,
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');
}
})
}
})
app.post('/addprojectoverview', function (req, res) {
if (req.isAuthenticated()) {
......@@ -304,10 +202,6 @@ module.exports = function (app) {
}
})
app.get('/updateprojectoverview', function (req, res) {
// only their own project
})
app.post('/updateprojectoverview', function (req, res) {
// only their own project
})
......@@ -356,12 +250,6 @@ module.exports = function (app) {
])
})
async function getProjectsFromGitlab(perPage, idAfter) {
// public projects
return await axios.get('https://transfer.hft-stuttgart.de/gitlab/api/v4/projects?visibility=public&pagination=keyset&per_page='+
perPage+'&order_by=id&sort=asc&id_after='+idAfter)
}
// Projektdaten
app.get('/projektdaten', async function(req, res){
let projectArr = []
......@@ -369,40 +257,32 @@ module.exports = function (app) {
let firstId = 0
while (isProject == true) {
let projects = await getProjectsFromGitlab(10, firstId)
let projectData = projects.data
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++){
// skip template project
if (projectData[i].name == "template_gitlab_page") {
continue
// 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 -"
}
// only repo
if (!projectData[i].tag_list.includes('website')) {
// 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)
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
}
}
......@@ -419,61 +299,58 @@ module.exports = function (app) {
let firstId = 0
while (isProject == true) {
let projects = await getProjectsFromGitlab(10, firstId)
let projectData = projects.data
let projects = await gitlab.getProjects(100, firstId)
let pagesData = projects.data[1]
if (projectData.length == 0) {
if (pagesData.length == 0) {
isProject = false
}
else {
for(let i = 0; i < projectData.length; i++){
// skip template project
if (projectData[i].name == "template_gitlab_page") {
continue
}
// websites
if (projectData[i].tag_list.includes('website')) {
} 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 (projectData[i].avatar_url == null) {
projectData[i].avatar_url = "https://m4lab.hft-stuttgart.de/img/footer/M4_LAB_LOGO_Graustufen.png"
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 (projectData[i].description == "") {
projectData[i].description = "- no description -"
if (pagesData[i].description == "") {
pagesData[i].description = "- no description -"
}
// customize website name
if (projectData[i].name == "Visualization") {
projectData[i].web_url = "https://transfer.hft-stuttgart.de/pages/visualization"
// 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 (projectData[i].name == "IN-Source") {
projectData[i].web_url = "https://transfer.hft-stuttgart.de/pages/INsource"
else if (pagesData[i].name == "IN-Source") {
//todo: update URL
pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/INsource"
}
else if (projectData[i].name == "3DS_Visualization_Cesium") {
projectData[i].web_url = "https://transfer.hft-stuttgart.de/pages/3ds_visualization_cesium"
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 {
projectData[i].web_url = "https://transfer.hft-stuttgart.de/pages/"+projectData[i].name
//todo: update URL
pagesData[i].web_url = "https://transfer.hft-stuttgart.de/pages/"+pagesData[i].name
}
// remove 'website' from tag list
const index = projectData[i].tag_list.indexOf('website');
let index = pagesData[i].tag_list.indexOf('website')
if (index > -1) {
projectData[i].tag_list.splice(index, 1);
pagesData[i].tag_list.splice(index, 1)
}
// fill in pagesArr
let pages = {
logo: projectData[i].avatar_url,
name: projectData[i].name,
weburl: projectData[i].web_url,
desc: projectData[i].description,
keywords: projectData[i].tag_list
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 = projectData[projectData.length-1].id
firstId = pagesData[pagesData.length-1].id
}
}
......
......@@ -4,8 +4,8 @@ html(lang="de")
title= "Projektinformationen"
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/bootstrap.min.css")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/m4lab.css")
link(rel="stylesheet", type="text/css", href="/css/bootstrap.min.css")
link(rel="stylesheet", type="text/css", href="/css/m4lab.css")
link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.8.2/css/all.css", integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay", crossorigin="anonymous")
style.
.title-container {
......
......@@ -4,8 +4,8 @@ html(lang="de")
title= "Projektdaten"
meta(charset="UTF-8")
meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/bootstrap.min.css")
link(rel="stylesheet", type="text/css", href="https://transfer.hft-stuttgart.de/css/m4lab.css")
link(rel="stylesheet", type="text/css", href="/css/bootstrap.min.css")
link(rel="stylesheet", type="text/css", href="/css/m4lab.css")
link(rel="stylesheet", href="https://use.fontawesome.com/releases/v5.8.2/css/all.css", integrity="sha384-oS3vJWv+0UjzBfQzYUhtDYW+Pj2yciDJxpsK1OYPAYjqT085Qq/1cq5FLXAZQ7Ay", crossorigin="anonymous")
style.
.title-container {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment