Commit beac6d0a authored by Johannes Zellner's avatar Johannes Zellner

Add project deletion ui

parent e7df8d24
......@@ -31,7 +31,9 @@ function getReleases(token, project, callback) {
// https://gitlab.example.com/api/v4/projects/24/releases
callback(new Error('not implemented'));
console.log('---', token, project)
callback(null, []);
}
function getCommit(token, project, sha, callback) {
......
......@@ -24,7 +24,8 @@ module.exports = exports = {
get: projectsGet,
add: projectAdd,
list: projectsList,
update: projectsUpdate
update: projectsUpdate,
del: projectsDelete
}
};
......@@ -167,7 +168,8 @@ function projectAdd(req, res, next) {
const project = {
type: req.body.type,
userId: req.user.id,
name: req.body.name
name: req.body.name,
origin: req.body.origin
};
database.projects.add(project, function (error, result) {
......@@ -198,3 +200,14 @@ function projectsUpdate(req, res, next) {
next(new HttpSuccess(202, {}));
});
}
function projectsDelete(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
assert.strictEqual(typeof req.params.projectId, 'string');
database.projects.remove(req.params.projectId, function (error) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(202, {}));
});
}
......@@ -27,6 +27,7 @@ function start(port, callback) {
router.post('/api/v1/projects', routes.auth, routes.projects.add);
router.get ('/api/v1/projects/:projectId', routes.auth, routes.projects.get);
router.post('/api/v1/projects/:projectId', routes.auth, routes.projects.update);
router.del ('/api/v1/projects/:projectId', routes.auth, routes.projects.del);
app
.use(connectTimeout(10000, { respond: true }))
......
......@@ -33,3 +33,14 @@ a:hover, a:focus {
.el-table a:hover {
color: #66b1ff;
}
.type-icon {
height: 24px;
vertical-align: middle;
padding-right: 10px;
filter: grayscale(0.5);
}
.type-icon:hover {
filter: grayscale(0);
}
\ No newline at end of file
......@@ -53,14 +53,19 @@
</template>
</el-table-column>
<el-table-column label="Type" sortable :sort-method="sort">
<template slot-scope="scope">{{ scope.row.type }}</template>
<template slot-scope="scope"><img :src="'/' + scope.row.type + '.svg'" class="type-icon"/> {{ scope.row.type }}</template>
</el-table-column>
<!-- <el-table-column prop="type" label="Type" width="150px"></el-table-column> -->
<el-table-column label="" align="right">
<template slot-scope="scope">
<el-tag type="danger" v-show="!scope.row.enabled">Notifications are disabled</el-tag>
<el-button type="text" size="small" @click="setProjectState(scope.row.id, !scope.row.enabled, scope)" style="width: 80px;"><i class="el-icon-loading" v-show="scope.row.busy"></i><span v-show="!scope.row.busy">{{ scope.row.enabled ? 'Disable' : 'Enable' }}</span></el-button>
</template></el-table-column>
</template>
</el-table-column>
<el-table-column label="" align="right">
<template slot-scope="scope">
<el-button type="text" size="small" @click="setProjectState(scope.row.id, !scope.row.enabled, scope)"><i class="el-icon-loading" v-show="scope.row.busy"></i><span v-show="!scope.row.busy">{{ scope.row.enabled ? 'Disable' : 'Enable' }}</span></el-button>
<el-button type="text" size="small" v-show="scope.row.type !== 'github'" @click="deleteProject(scope.row.id, scope)"><i class="el-icon-loading" v-show="scope.row.busy"></i><span v-show="!scope.row.busy"> Delete</el-button>
</template>
</el-table-column>
</el-table>
</el-col>
</el-row>
......@@ -85,12 +90,11 @@
<el-form ref="form" label-width="120px" @submit.native.prevent>
<el-form-item label="Type" required>
<el-select v-model="addProject.type" placeholder="Select">
<el-option key="github" label="Github" value="github"></el-option>
<el-option key="github" label="Github" value="github" ></el-option>
<el-option key="gitlab" label="GitLab" value="gitlab"></el-option>
<el-option key="website" label="Website" value="website"></el-option>
</el-select>
</el-form-item>
<el-form-item label="Name" required><el-input v-model="addProject.name" type="text"></el-input></el-form-item>
<el-form-item label="Url" required><el-input v-model="addProject.url" type="text"></el-input></el-form-item>
<el-form-item><el-button type="primary" native-type="submit" @click="onProjectAdd" style="width: 120px;" :disabled="addProject.busy"><i class="el-icon-loading" v-show="addProject.busy"></i><span v-show="!addProject.busy">Save</span></el-button></el-form-item>
<input type="submit" @click="onProjectAdd" v-show="false"/>
......
......@@ -20,7 +20,6 @@ new Vue({
addProject: {
busy: false,
type: '',
name: '',
url: ''
}
},
......@@ -89,14 +88,20 @@ new Vue({
onProjectAdd: function () {
var that = this;
if (!this.addProject.name || !this.addProject.url) return;
var url = new URL(this.addProject.url);
console.log('Add Project', this.addProject.name, this.addProject.url, this.addProject.type);
var components = url.pathname.split('/');
if (components.length < 3) return console.error('Invalid gitlab url');
var origin = url.origin;
var name = components[1] + '/' + components[2];
console.log('Add Project', name, origin, this.addProject.type);
var data = {
type: this.addProject.type,
name: this.addProject.name,
url: this.addProject.url
name: name,
origin: origin
}
this.addProject.busy = true;
......@@ -129,6 +134,16 @@ new Vue({
this.login.password = '';
}
},
refreshProjects: function () {
var that = this;
superagent.get('/api/v1/projects').query({ username: that.login.username, password: that.login.password }).end(function (error, result) {
if (error) return that.onError(error);
if (result.statusCode !== 200) return that.onError('Unexpected response: ' + result.statusCode + ' ' + result.text);
that.projects = result.body.projects;
});
},
prettyDate: function (row, column, cellValue, index) {
if (!cellValue) return '';
......@@ -166,6 +181,21 @@ new Vue({
that.projects.find(function (p) { return p.id === projectId; }).enabled = state;
});
},
deleteProject: function (projectId, scope) {
var that = this;
scope.row.busy = true;
superagent.delete('/api/v1/projects/' + projectId).query({ username: that.login.username, password: that.login.password }).end(function (error, result) {
scope.row.busy = false;
if (error) return that.onError(error);
if (result.statusCode !== 202) return that.onError('Unexpected response: ' + result.statusCode + ' ' + result.text);
// update the ui now
that.refreshProjects();
});
},
sort: function (a, b) {
// default sorting uses case-sensitive sorting
return a.name.toUpperCase() < b.name.toUpperCase();
......
'use strict';
exports.up = function(db, callback) {
db.runSql('ALTER TABLE projects ADD COLUMN origin VARCHAR(512) NOT NULL DEFAULT ""', callback);
};
exports.down = function(db, callback) {
db.runSql('ALTER TABLE projects DROP COLUMN type', callback);
};
-- Only for reference
CREATE TABLE IF NOT EXISTS users(
id VARCHAR(128) NOT NULL UNIQUE,
email VARCHAR(512) NOT NULL,
githubToken VARCHAR(512) NOT NULL DEFAULT "",
PRIMARY KEY(id));
CREATE TABLE IF NOT EXISTS projects(
id VARCHAR(128) NOT NULL UNIQUE,
userId VARCHAR(128) NOT NULL,
name VARCHAR(512) NOT NULL,
origin VARCHAR(512) NOT NULL DEFAULT "",
enabled BOOLEAN DEFAULT true,
lastSuccessfulSyncAt BIGINT DEFAULT 0,
type VARCHAR(32) NOT NULL DEFAULT "github",
FOREIGN KEY(userId) REFERENCES users(id),
PRIMARY KEY(id));
CREATE TABLE IF NOT EXISTS releases(
id VARCHAR(128) NOT NULL UNIQUE,
projectId VARCHAR(128) NOT NULL,
version VARCHAR(512) NOT NULL,
notified BOOLEAN DEFAULT false,
createdAt BIGINT NOT NULL,
FOREIGN KEY(projectId) REFERENCES projects(id),
PRIMARY KEY(id));
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