Skip to content
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

created model and migrations for teams and teams overview #532

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ app.use(
require('./lib/route/calendar')
);

app.use('/teams/', require('./lib/route/teams'))

app.use(
'/settings/',
require('./lib/route/settings')
Expand Down
32 changes: 32 additions & 0 deletions lib/model/db/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"use strict";

module.exports = function (sequelize, DataTypes) {
var Team = sequelize.define(
"Team",
{
name: {
type: DataTypes.STRING,
allowNull: false,
},
description: {
type: DataTypes.STRING,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
},
updatedAt: {
type: DataTypes.DATE,
allowNull: false,
},
},
{
indexes: [
{
fields: ["id"],
},
],
}
);
return Team;
};
45 changes: 45 additions & 0 deletions lib/route/teams/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@

"use strict";

const
express = require('express'),
router = express.Router(),
validator = require('validator'),
Promise = require('bluebird'),
moment = require('moment'),
Exception = require('../../error')

router.all(/.*/, require('../../middleware/ensure_user_is_admin'));

router.get('/', function(req, res) {
const tribes = [
{id: 1, name: 'Green Owl'},
{id: 2, name: 'Rogue Squad'}
]
req.user
.get_company_for_add_user()
.then(function(company) {
res.render('team_add', {
company: company,
teams: [
{
id: 1,
name: 'benchWarmers',
users: [{id: 1}, {id: 2 }, {id: 3}],
client: {id: 1, name: 'Fruitful' },
tribe: {id: 1, name: 'Green Owl'}
},
{
id: 2,
name: 'Lazuli',
users: [{id: 4}, {id: 5 }],
client: {id: 2, name: 'Internal' },
tribe: {id: 2, name: 'Green Owl'}
}
],
tribes: tribes
})
})
})

module.exports = router;
34 changes: 34 additions & 0 deletions migrations/20221021150739-create-team-table.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
'use strict';

const { sequelize } = require("../lib/model/db");

module.exports = {
up: function (queryInterface, Sequelize) {
return queryInterface.createTable('Teams', {
id: {
type: Sequelize.DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true,
},
name: {
type: Sequelize.DataTypes.STRING,
allowNull: false
},
description: {
type: Sequelize.DataTypes.STRING
},
createdAt: {
type: Sequelize.DataTypes.DATE,
defaultValue: Sequelize.NOW
},
updatedAt: {
type: Sequelize.DataTypes.DATE,
defaultValue: Sequelize.NOW
}
});
},

down: function (queryInterface, Sequelize) {
return queryInterface.dropTable('Teams');
}
};
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
"passport-http-bearer": "^1.0.1",
"passport-local": "^1.0.0",
"redis": "^3.1.2",
"sequelize": "^3.19.2",
"sequelize": "^3.35.1",
"sequelize-cli": "2.5.1",
"serve-favicon": "^2.1.7",
"sqlite3": "^4.0.1",
"sqlite3": "^5.1.2",
"underscore": "^1.8.3",
"uuid": "^3.3.2",
"validator": "^3.43.0"
Expand Down
37 changes: 37 additions & 0 deletions views/partials/add_new_team_modal.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

<div class="modal fade" id="{{container_id}}" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<form method="POST" action="{{form_action}}" id="add_new_department_form">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
<h4 class="modal-title">Add new Team</h4>
</div>

<div class="modal-body">

<div class="form-group">
<label for="department_name_new" class="control-label">Name:</label>
<input type="text" class="form-control" id="department_name_new" name="name__new" required placeholder="New team name">
</div>

<div class="form-group">
<label for="department_allowance_new" class="control-label">Select Tribe:</label>
<select class="form-control" id="department_allowance_new" name="allowance__new">
{{#each tribes}}
<option value="{{name}}">{{this.name}}</option>
{{/each}}
</select>
</div>

</div>
<div class="modal-footer">
<button type="button" class="btn btn-link" data-dismiss="modal">Cancel</button>
<button type="submit" class="btn btn-success single-click">Create</button>
</div>
</form>
</div>
</div>
</div>


1 change: 1 addition & 0 deletions views/partials/header.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<li><a href="/settings/general/">General</a></li>
<li role="separator" class="divider"></li>
<li><a href="/settings/departments/">Departments</a></li>
<li><a href="/teams/">Teams</a></li>
<li><a href="/settings/bankholidays/">Bank Holidays</a></li>
<li><a href="/settings/company/authentication/">LDAP configuration</a></li>
<li><a href="/settings/company/integration-api/">API configuration</a></li>
Expand Down
51 changes: 51 additions & 0 deletions views/team_add.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

{{> header }}

<h1>Teams</h1>

<div class="row">
<div class="col-md-4 lead">All teams</div>
<div class="col-md-4 col-md-offset-4">
<button class="btn btn-info pull-right" data-toggle="modal" data-target="#add_new_team_modal" type="button" id="add_new_team_btn">Add new team</button>
</div>
</div>

<div class="row">&nbsp;</div>

{{# unless teams.length }}
<div class="row">
<div class="col-md-4">No team records</div>
</div>
{{/unless}}

<div class="row">
<div class="col-md-12">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>Number of members</th>
<th>Client</th>
<th>Tribe</th>
</tr>
</thead>
<tbody>
{{#each teams}}
<tr>
<td><a href="/teams/edit/{{this.id}}/" data-vpp-team-name=1>{{this.name}}</a></td>
<td>{{ this.users.length }}</td>
<th>{{ this.client.name }}</th>
<th>{{ this.tribe.name }}</th>
</tr>
{{/each}}
</tbody>
</table>
</div>
</div>

{{> add_new_team_modal
container_id='add_new_team_modal'
form_action='/teams/add/'
}}

{{> footer}}