New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #357 Create settings page for repositories #361

Merged
merged 1 commit into from Aug 8, 2017
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+202 −15
Diff settings

Always

Just for now

Copy path View file
@@ -14,7 +14,10 @@ const repositorySchema = new mongoose.Schema({
},
accessToken: String,
buildStatus: Boolean,
mailService: Boolean,
mailService: {
status: Boolean,
email: String,
},
hook: String,
enable: {
type: Boolean,
@@ -0,0 +1,44 @@
$(function() {
const predefinedMessages = {
'mail_disabled_successful': "Mail service disabled for this repository",
'mail_enabled_successful': "Mail service enabled for this repository",
'mail_changed_successful': "Email address associated with this repository changed successfully",
};

if ((predefinedMessages[styles.getParameterByName("status")] || '') !== '') {
styles.showNotification(predefinedMessages[styles.getParameterByName("status")]);
window.history.pushState("", "", location.pathname);
}


$('.open-delete-modal').click(function () {
$('#repository-name').val('');
styles.disableButton("btnDelete");
setTimeout(function(){
$('#repository-name').focus();
},500);
$(".modal-body #name-code").html($(this).data('name'));
});

$('#repository-name').keyup(function () {
var reponame = $('.modal-body #name-code').html();
var name = $('#repository-name').val();

if (name === reponame) {
styles.enableButton("btnDelete");
} else {
styles.disableButton("btnDelete");
}

});

$('.open-disable-modal').click(function () {
$("#disableInput").val($(this).data('name'));
$("#disableBtnYes").click(function () {
$("#disableForm").submit();
});
$("#disableBtnClose").click(function () {
$("#disableModal").modal('hide');
});
});
});
Copy path View file
@@ -86,7 +86,10 @@ router.post('/register', function (req, res, next) {
login: req.user.username
},
accessToken: token,
mailService: true,
mailService: {
status: true,
email: req.user.email,
},
hook: body.id,
};
} else {
Copy path View file
@@ -1,8 +1,9 @@
var express = require("express");
var router = express.Router();

var hostname = process.env.HOSTNAME || 'yaydoc.herokuapp.com';
var authMiddleware = require("../middleware/auth");

var hostname = process.env.HOSTNAME || 'yaydoc.herokuapp.com';

Repository = require("../model/repository");
BuildLog = require("../model/buildlog");
@@ -67,15 +68,16 @@ router.get('/:owner/:reponame.svg', function (req, res, next) {

router.get('/:owner/:reponame', function (req, res, next) {
Repository.getRepositoryWithLatestLogs(req.params.owner + '/' + req.params.reponame, function (error, result) {
if (result[0] === null || error) {
if (!result[0]|| error) {
return res.status(404).render('repository/404');
}

if (result[0].logs === null) {
return res.status(404).render('repository/404');
}

res.render('repository/index', {title: result[0].name + ' | Yaydoc',
res.render('repository/index', {
title: result[0].name + ' | Yaydoc',
repository: result[0],
hostname: hostname,
});
@@ -88,12 +90,26 @@ router.get('/:owner/:reponame/logs', function (req, res, next) {
return res.status(404).render('repository/404');
}

res.render('repository/logs', {title: result[0].name + ' | Yaydoc',
res.render('repository/logs', {
title: 'Logs - ' + result[0].name + ' | Yaydoc',
repository: result[0],
buildLogs: result,
hostname: hostname,
});
});
});

router.get('/:owner/:reponame/settings', authMiddleware.isLoggedIn, function (req, res, next) {
Repository.getRepositoryByName(req.params.owner + '/' + req.params.reponame, function (error, repository) {
if (repository === null || error) {
return res.status(404).render('repository/404');
}

res.render('repository/settings', {
title: 'Settings - ' + repository.name + ' | Yaydoc',
repository: repository
});
});
});

module.exports = router;
Copy path View file
@@ -74,4 +74,43 @@ router.post("/enable", authMiddleware.isLoggedIn, function(req, res, next) {
});
});

router.post('/mail/disable', authMiddleware.isLoggedIn, function (req, res, next) {
Repository.updateRepository({name: req.body.repository}, {'mailService.status': false})
.then(function () {
res.redirect('/' + req.body.repository + '/settings?status=mail_disabled_successful');
})
.catch(function () {
next({
status: 500,
messages: 'Something went wrong'
});
});
});

router.post('/mail/enable', authMiddleware.isLoggedIn, function (req, res, next) {
Repository.updateRepository({name: req.body.repository}, {'mailService.status': true})
.then(function () {
res.redirect('/' + req.body.repository + '/settings?status=mail_enabled_successful');
})
.catch(function () {
next({
status: 500,
messages: 'Something went wrong'
});
});
});

router.post('/mail', authMiddleware.isLoggedIn, function (req, res, next) {
Repository.updateRepository({name: req.body.repository}, {'mailService.email': req.body.email})
.then(function () {
res.redirect('/' + req.body.repository + '/settings?status=mail_changed_successful');
})
.catch(function () {
next({
status: 500,
messages: 'Something went wrong'
});
});
});

module.exports = router;
Copy path View file
@@ -68,15 +68,18 @@ block content
each repository in ownedRepositories
tr
td #{repository.name}
td
td(style="width:0;vertical-align: middle")
a(href="/#{repository.name}/settings")
i.fa.fa-gear.fa-2x
td(style="width:0")
if repository.enable === true
button.btn.btn-warning.open-disable-modal(data-toggle="modal" data-name="#{repository.name}" href="#disableModal") Disable
else
form(method="POST" action="/repository/enable")
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-primary(type="submit") Enable
td
button.btn.btn-danger.open-delete-modal(data-toggle="modal" data-name="#{repository.name}" href="#deleteModal" data-backdrop="static" data-keyboard="false") Delete
td(style="width:0")
button.close.open-delete-modal(data-toggle="modal" data-name="#{repository.name}" href="#deleteModal" data-backdrop="static" data-keyboard="false" style="color:red; font-size:30px") ×
else
p No repositories registered!
if organizations
@@ -87,16 +90,20 @@ block content
if organization.repositories && organization.repositories.length !== 0
each repository in organization.repositories
tr
td #{repository.name}
td
td(style="vertical-align: middle") #{repository.name}
td(style="width:0;vertical-align: middle")
a(href="/#{repository.name}/settings")
i.fa.fa-gear.fa-2x
td(style="width:0")
if repository.enable === true
button.btn.btn-warning.open-disable-modal(data-toggle="modal" data-name="#{repository.name}" href="#disableModal") Disable
else
form(method="POST" action="/repository/enable")
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-primary(type="submit") Enable
td
button.btn.btn-danger.open-delete-modal(data-toggle="modal" data-name="#{repository.name}" href="#deleteModal" data-backdrop="static" data-keyboard="false") Delete
button.btn.btn-primary(type="submit") Enable
td(style="width:0")
button.close.open-delete-modal(data-toggle="modal" data-name="#{repository.name}" href="#deleteModal" data-backdrop="static" data-keyboard="false" style="color:red; font-size:30px") ×

else
p No repositories registered!
.modal.fade#deleteModal(role='dialog')
@@ -129,4 +136,3 @@ block content
.modal-footer
button.btn.btn-default#disableBtnClose(type="button") Close
button.btn.btn-primary#disableBtnYes(type="button") Yes...Disable

Copy path View file
@@ -5,6 +5,7 @@ html
link(rel='stylesheet', href='/stylesheets/style.css')
link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css')
link(rel='stylesheet', href='//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.css')
link(rel='stylesheet', href='https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css')
script(src='https://code.jquery.com/jquery-1.11.1.js')
script(src='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js')
script(src='//rawgithub.com/indrimuska/jquery-editable-select/master/dist/jquery-editable-select.min.js')
Copy path View file
@@ -0,0 +1,75 @@
extends ../layout

block content
script.
var repository = #{repository}
script(src="/scripts/socket-repository.js")
.container
h2
| #{repository.name}  
a(href='https://github.com/#{repository.name}' target="_blank")
span.glyphicon.glyphicon-link
|  
img(src='/#{repository.name}.svg' data-toggle="modal" data-target="#statustag-modal" style='cursor: pointer')
ul.nav.nav-tabs(style="margin-bottom: 10px")
li
a(href="/#{repository.name}") Latest Log
li
a(href="/#{repository.name}/logs") Log History
li.active
a(href="/#{repository.name}/settings") Settings
h3 General
p Placeholder for general settings
hr
h3 Mail Service
if repository.mailService.status
form(method="POST" action="/repository/mail/disable").form-inline
.form-group
label.control-label Status: 
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-warning Disable
else
form(method="POST" action="/repository/mail/enable").form-inline
.form-group
label.control-label Status: 
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-primary Enable
form(method="POST" action="/repository/mail").form-inline
.form-group
label(for="email") Email: 
input(type="hidden", name="repository", value="#{repository.name}")
input.form-control#email(type="email" name="email" value="#{repository.mailService.email}")
button.btn.btn-default(type="submit") Save
hr
h3 Danger Zone
if repository.enable
form(method="POST" action="/repository/disable").form-inline
.form-group
label.control-label Repository Status: 
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-warning Disable
else
form(method="POST" action="/repository/enable").form-inline
.form-group
label.control-label Repository Status: 
input(type="hidden", name="repository", value="#{repository.name}")
button.btn.btn-primary Enable
.form-group
label.control-label Delete Repository: 
button.btn.btn-danger.open-delete-modal(data-toggle="modal" data-name="#{repository.name}" href="#deleteModal" data-backdrop="static" data-keyboard="false") Delete
.modal.fade#deleteModal(role='dialog')
.modal-dialog
.modal-content
form(action="/repository/delete" method="post")
.modal-header
button.close(type='button', data-dismiss='modal') ×
h4.modal-title Are you sure you want to delete?
.modal-body
p
| Enter your repository's name (
code#name-code
| ) below to confirm you want to permanently remove it from Yaydoc:
.form-group
input.form-control#repository-name(name="name" autofocus)
.modal-footer
button.btn.btn-default#btnDelete(disabled="disabled") Delete
ProTip! Use n and p to navigate between commits in a pull request.