Skip to content

Commit bf4b6bd

Browse files
committed
Project Roles/Applications
WIP -- Roles for projects where users can apply for a position (role).
1 parent 749aa7e commit bf4b6bd

File tree

10 files changed

+564
-7
lines changed

10 files changed

+564
-7
lines changed

html-templates/projects/project.tpl

Lines changed: 255 additions & 4 deletions
Large diffs are not rendered by default.

html-templates/projects/roleAdded.tpl

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{extends designs/site.tpl}
2+
3+
{block title}{_ "Roles"} — {$dwoo.parent}{/block}
4+
5+
{block content}
6+
{capture assign=project}{projectLink $Project}{/capture}
7+
8+
<div class="page-header">
9+
<h1>Role Added</h1>
10+
</div>
11+
<p class="lead">{sprintf(_("%s has been added to %s"), $data->Role, $project)}</p>
12+
{/block}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{extends designs/site.tpl}
2+
3+
{block title}{_ "Roles"} &mdash; {$dwoo.parent}{/block}
4+
5+
{block content}
6+
{capture assign=project}{projectLink $Project}{/capture}
7+
8+
<div class="page-header">
9+
<h1>Application Added</h1>
10+
</div>
11+
<p class="lead">{sprintf(_(Your application for "%s has been added to %s"), $data->Role, $project)}</p>
12+
{/block}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{extends designs/site.tpl}
2+
3+
{block title}{_ "Roles"} &mdash; {$dwoo.parent}{/block}
4+
5+
{block content}
6+
{capture assign=project}{projectLink $Project}{/capture}
7+
8+
<div class="page-header">
9+
<h1>Role Modified</h1>
10+
</div>
11+
<p class="lead">{sprintf(_("%s has been modified for %s"), $data->Role, $project)}</p>
12+
{/block}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{extends designs/site.tpl}
2+
3+
{block title}Roles &mdash; {$dwoo.parent}{/block}
4+
5+
{block content}
6+
<div class="row">
7+
<div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
8+
<div class="page-header">
9+
<h1>Role Removed</h1>
10+
</div>
11+
<p>{if $data && $data->Role}({$data->Role|escape}){/if} has been removed from {projectLink $Project}</p>
12+
</div>
13+
</div>
14+
{/block}

php-classes/Laddr/Project.php

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,27 @@ class Project extends \VersionedRecord
8484
'linkForeign' => 'MemberID',
8585
'indexField' => 'ID'
8686
],
87+
'Roles' => [
88+
'type' => 'one-many',
89+
'class' => ProjectRole::class,
90+
'foreign' => 'ProjectID'
91+
],
92+
'OpenRoles' => [
93+
'type' => 'one-many',
94+
'class' => ProjectRole::class,
95+
'foreign' => 'ProjectID',
96+
'conditions' => [
97+
'PersonID IS NULL'
98+
]
99+
],
100+
'FilledRoles' => [
101+
'type' => 'one-many',
102+
'class' => ProjectRole::class,
103+
'foreign' => 'ProjectID',
104+
'conditions' => [
105+
'PersonID IS NOT NULL'
106+
]
107+
],
87108
'Memberships' => [
88109
'type' => 'one-many',
89110
'class' => ProjectMember::class,
@@ -142,6 +163,7 @@ class Project extends \VersionedRecord
142163
public static $dynamicFields = [
143164
'Maintainer',
144165
'Members',
166+
'Roles',
145167
'Memberships',
146168
'Tags',
147169
'TopicTags',
@@ -192,9 +214,9 @@ public function save($deep = true)
192214
parent::save($deep);
193215

194216
if (!$this->Members) {
195-
ProjectMember::create([
217+
ProjectRole::create([
196218
'ProjectID' => $this->ID,
197-
'MemberID' => $this->Maintainer->ID,
219+
'PersonID' => $this->Maintainer->ID,
198220
'Role' => 'Founder' // _("Founder") -- placeholder to make this string translatable, actual translation is done during rendering though
199221
], true);
200222
}

php-classes/Laddr/ProjectRole.php

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Laddr;
4+
5+
use Emergence\People\Person;
6+
7+
8+
class ProjectRole extends \ActiveRecord
9+
{
10+
// ActiveRecord configuration
11+
public static $tableName = 'project_roles'; // the name of this model's table
12+
13+
// controllers will use these values to figure out what templates to use
14+
public static $singularNoun = 'project role'; // a singular noun for this model's object
15+
public static $pluralNoun = 'project roles'; // a plural noun for this model's object
16+
17+
// gets combined with all the extended layers
18+
public static $fields = [
19+
'ProjectID' => 'uint',
20+
'PersonID' => [
21+
'type' =>'uint',
22+
'default'=>null
23+
],
24+
'Role' => 'string',
25+
'Description' => [
26+
'type' =>'string',
27+
'default'=>null
28+
]
29+
];
30+
31+
public static $relationships = [
32+
'Project' => [
33+
'type' => 'one-one',
34+
'class' => Project::class
35+
],
36+
'Person' => [
37+
'type' => 'one-one',
38+
'class' => Person::class
39+
]
40+
];
41+
42+
public static $dynamicFields = [
43+
'Project',
44+
'Person'
45+
];
46+
}

php-classes/Laddr/ProjectsRequestHandler.php

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ class ProjectsRequestHandler extends \RecordsRequestHandler
1818
public static function handleRecordRequest(\ActiveRecord $Project, $action = false)
1919
{
2020
switch ($action ? $action : $action = static::shiftPath()) {
21+
case 'add-role':
22+
return static::handleAddRoleRequest($Project);
23+
case 'modify-role':
24+
return static::handleModifyRoleRequest($Project);
25+
case 'remove-role':
26+
return static::handleRemoveRoleRequest($Project);
27+
case 'add-application':
28+
return static::handleAddRoleApplicationRequest($Project);
2129
case 'add-member':
2230
return static::handleAddMemberRequest($Project);
2331
case 'remove-member':
@@ -84,6 +92,104 @@ public static function handleBrowseRequest($options = [], $conditions = [], $res
8492
return parent::handleBrowseRequest($options, $conditions, $responseID, $responseData);
8593
}
8694

95+
public static function handleAddRoleRequest(Project $Project)
96+
{
97+
$GLOBALS['Session']->requireAuthentication();
98+
99+
$Person = User::getByUsername($_POST['username']);
100+
101+
$recordData = [
102+
'ProjectID' => $Project->ID,
103+
'PersonID' => (!$Person)?null:$Person->ID
104+
];
105+
106+
$ProjectRole = ProjectRole::create($recordData);
107+
108+
if (!empty($_POST['role'])) {
109+
$ProjectRole->Role = $_POST['role'];
110+
}
111+
112+
if (!empty($_POST['description'])) {
113+
$ProjectRole->Description = $_POST['description'];
114+
}
115+
116+
$ProjectRole->save();
117+
118+
return static::respond('roleAdded', [
119+
'data' => $ProjectRole,
120+
'Project' => $Project,
121+
'Member' => $Person
122+
]);
123+
}
124+
125+
public static function handleModifyRoleRequest(Project $Project)
126+
{
127+
$GLOBALS['Session']->requireAuthentication();
128+
129+
$Person = User::getByUsername($_POST['username']);
130+
131+
$recordData = [
132+
'ProjectID' => $Project->ID,
133+
'PersonID' => (!$Person)?null:$Person->ID
134+
];
135+
136+
$ProjectRole = ProjectRole::create($recordData);
137+
138+
if (!empty($_POST['role'])) {
139+
$ProjectRole->Role = $_POST['role'];
140+
}
141+
142+
if (!empty($_POST['description'])) {
143+
$ProjectRole->Description = $_POST['description'];
144+
}
145+
146+
$ProjectRole->save();
147+
148+
return static::respond('roleModified', [
149+
'data' => $ProjectRole,
150+
'Project' => $Project,
151+
'Member' => $Person
152+
]);
153+
}
154+
155+
public static function handleAddRoleApplicationRequest(Project $Project){
156+
$GLOBALS['Session']->requireAuthentication();
157+
158+
}
159+
160+
public static function handleRemoveRoleRequest(Project $Project)
161+
{
162+
$GLOBALS['Session']->requireAuthentication();
163+
164+
if (empty($_REQUEST['role_id'])) {
165+
return static::throwError(_('Parameter "role_id" required'));
166+
}
167+
168+
$ProjectRole = ProjectRole::getByWhere([
169+
'ProjectID' => $Project->ID,
170+
'ID' => $_REQUEST['role_id']
171+
]);
172+
173+
if ($_SERVER['REQUEST_METHOD'] != 'POST') {
174+
return static::respond('confirm', [
175+
'question' => sprintf(
176+
_('Are you sure you want to remove %s from %s?'),
177+
htmlspecialchars($Role->Role),
178+
htmlspecialchars($Project->Title)
179+
)
180+
]);
181+
}
182+
183+
if ($ProjectRole) {
184+
$ProjectRole->destroy();
185+
}
186+
187+
return static::respond('roleRemoved', [
188+
'data' => $ProjectRole,
189+
'Project' => $Project
190+
]);
191+
}
192+
87193
public static function handleAddMemberRequest(Project $Project)
88194
{
89195
$GLOBALS['Session']->requireAuthentication();

php-classes/Laddr/RoleApplication.php

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
namespace Laddr;
4+
5+
use Emergence\People\Person;
6+
7+
8+
class RoleApplication extends \ActiveRecord
9+
{
10+
// ActiveRecord configuration
11+
public static $tableName = 'role_applications'; // the name of this model's table
12+
13+
// controllers will use these values to figure out what templates to use
14+
public static $singularNoun = 'role application'; // a singular noun for this model's object
15+
public static $pluralNoun = 'role applications'; // a plural noun for this model's object
16+
17+
// gets combined with all the extended layers
18+
public static $fields = [
19+
'ProjectID' => 'uint',
20+
'PersonID' => 'uint',
21+
'RoleID' => 'uint',
22+
'Application' => 'string',
23+
'Status' => [
24+
'type' => 'enum',
25+
'values' => [
26+
'Pending',
27+
'Accepted',
28+
'Rejected'
29+
],
30+
'default' => 'Pending'
31+
]
32+
];
33+
34+
public static $relationships = [
35+
'Project' => [
36+
'type' => 'one-one',
37+
'class' => Project::class
38+
],
39+
'Person' => [
40+
'type' => 'one-one',
41+
'class' => Person::class
42+
],
43+
'ProjectRole' => [
44+
'type' => 'one-one',
45+
'class' => ProjectRole::class
46+
]
47+
];
48+
49+
public static $indexes = [
50+
'ProjectRoleApplication' => [
51+
'fields' => ['ProjectID', 'PersonID', 'RoleID'],
52+
'unique' => true
53+
]
54+
];
55+
56+
public static $dynamicFields = [
57+
'Project',
58+
'Person',
59+
'Role'
60+
];
61+
}

site-root/js/pages/project.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,25 @@
3232
epicEditor.importFile('README', $textarea.val());
3333
});
3434
});
35-
})();
35+
})();
36+
37+
$( "#open_role_table" ).on( "click", "a[title^='Apply']", function( event ) {
38+
$('#add-application').modal({show: 'true'});
39+
$("#inputRoleId").val($( this ).attr( "data-role_id"));
40+
});
41+
42+
$( "#open_role_table" ).on( "click", "a[title^='Edit Role']", function( event ){
43+
$('#modify-role').modal({show: 'true'});
44+
$("#inputRoleId").val($( this ).attr( "data-role_id"));
45+
$("#inputRole").val($( this ).attr( "data-role_name"));
46+
$("#inputRoleDescription").val($( this ).attr( "data-role_description"));
47+
$("#inputUsername").val($( this ).attr( "data-role_person"));
48+
});
49+
50+
$( "#role_table" ).on( "click", "a[title^='Edit Role']", function( event ) {
51+
$('#modify-role').modal({show: 'true'});
52+
$("#inputRoleId").val($( this ).attr( "data-role_id"));
53+
$("#inputRole").val($( this ).attr( "data-role_name"));
54+
$("#inputRoleDescription").val($( this ).attr( "data-role_description"));
55+
$("#inputUsername").val($( this ).attr( "data-role_person"));
56+
});

0 commit comments

Comments
 (0)