Commit dcd2dc1f authored by Johannes Zellner's avatar Johannes Zellner

Add project type to db

parent f18acee3
......@@ -7,6 +7,10 @@ var assert = require('assert'),
module.exports = exports = {
init: init,
PROJECT_TYPE_GITHUB: 'github',
PROJECT_TYPE_GITLAB: 'gitlab',
PROJECT_TYPE_WEBSITE: 'website',
users: {
list: usersList,
add: usersAdd,
......
......@@ -21,8 +21,9 @@ module.exports = exports = {
},
projects: {
list: projectsList,
get: projectsGet,
add: projectAdd,
list: projectsList,
update: projectsUpdate
}
};
......@@ -157,6 +158,25 @@ function projectsList(req, res, next) {
});
}
function projectAdd(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
if (!req.body.type) return next(new HttpError(400, 'type is required'));
if ([ database.PROJECT_TYPE_GITHUB, database.PROJECT_TYPE_GITLAB, database.PROJECT_TYPE_WEBSITE ].indexOf(req.body.type) === -1) return next(new HttpError(400, 'invalid type'));
const project = {
type: req.body.type,
userId: req.user.id,
name: req.body.name
};
database.projects.add(project, function (error, result) {
if (error) return next(new HttpError(500, error));
next(new HttpSuccess(201, { project: result }));
});
}
function projectsGet(req, res, next) {
assert.strictEqual(typeof req.user, 'object');
assert.strictEqual(typeof req.params.projectId, 'string');
......
......@@ -24,6 +24,7 @@ function start(port, callback) {
router.get ('/api/v1/profile', routes.auth, routes.profile.get);
router.post('/api/v1/profile', routes.auth, routes.profile.update);
router.get ('/api/v1/projects', routes.auth, routes.projects.list);
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);
......
......@@ -101,7 +101,7 @@ function syncStarredByUser(user, callback) {
debug(`syncStarredByUser: [${project.name}] is new for user ${user.id}`);
// we add projects first with release notification disabled
database.projects.add({ userId: user.id, name: project.name }, function (error, result) {
database.projects.add({ type: database.PROJECT_TYPE_GITHUB, userId: user.id, name: project.name }, function (error, result) {
if (error) return callback(error);
// force an initial release sync
......@@ -178,6 +178,11 @@ function syncReleasesByUser(user, callback) {
database.projects.list(user.id, function (error, result) {
if (error) return callback(error);
if (result.type !== database.PROJECT_TYPE_GITHUB) {
debug(`syncReleasesByUser: ignoring ${result.name} of type ${result.type} for now`);
return callback();
}
async.eachSeries(result, function (project, callback) {
syncReleasesByProject(user, project, callback);
}, function (error) {
......
......@@ -23,6 +23,7 @@
<el-menu-item index="projects" v-show="profile">Projects</el-menu-item>
<el-menu-item index="profile" v-show="profile">Profile</el-menu-item>
<el-menu-item index="logout" v-show="profile" style="float: right" @click="onLogout">Logout</el-menu-item>
<el-menu-item index="projectAdd" v-show="profile" style="float: right"><el-button type="primary">Add Project</el-button></el-menu-item>
</el-menu>
</el-header>
<el-main>
......@@ -48,6 +49,10 @@
<a :href="'https://github.com/' + scope.row.name" target="_blank">{{ scope.row.name }}</a>
</template>
</el-table-column>
<el-table-column label="Type" sortable :sort-method="sort">
<template slot-scope="scope">{{ 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>
......@@ -66,7 +71,26 @@
<el-input v-model="profile.githubToken" ref="githubTokenInput"></el-input>
<a href="https://github.com/settings/tokens/new?description=ReleaseBell" target="_blank">Generate a GitHub API token</a>
</el-form-item>
<el-form-item><el-button type="primary" native-type="submit" @click="onProfileSubmit" style="width: 120px;" :disabled="profileSubmitBusy"><i class="el-icon-loading" v-show="profileSubmitBusy"></i><span v-show="!profileSubmitBusy">Save<span></span></el-button></el-form-item>
<el-form-item><el-button type="primary" native-type="submit" @click="onProfileSubmit" style="width: 120px;" :disabled="profileSubmitBusy"><i class="el-icon-loading" v-show="profileSubmitBusy"></i><span v-show="!profileSubmitBusy">Save</span></el-button></el-form-item>
</el-form>
</el-col>
</el-row>
</div>
<div v-else-if="activeView === 'projectAdd'">
<el-row type="flex" justify="center">
<el-col style="max-width: 600px">
<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="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"/>
</el-form>
</el-col>
</el-row>
......
......@@ -16,7 +16,13 @@ new Vue({
loginSubmitBusy: false,
projects: null,
profile: {},
profileSubmitBusy: false
profileSubmitBusy: false,
addProject: {
busy: false,
type: '',
name: '',
url: ''
}
},
methods: {
onError: function (error) {
......@@ -80,6 +86,29 @@ new Vue({
else that.$message.success('Saved');
});
},
onProjectAdd: function () {
var that = this;
if (!this.addProject.name || !this.addProject.url) return;
console.log('Add Project', this.addProject.name, this.addProject.url, this.addProject.type);
var data = {
type: this.addProject.type,
name: this.addProject.name,
url: this.addProject.url
}
this.addProject.busy = true;
superagent.post('/api/v1/projects/').query({ username: that.login.username, password: that.login.password }).send(data).end(function (error, result) {
that.addProject.busy = false;
if (error) return that.onError(error);
if (result.statusCode !== 201) return that.onError('Unexpected response: ' + result.statusCode + ' ' + result.text);
that.handleViewSelect('projects');
});
},
handleViewSelect: function (key) {
var that = this;
......
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