Skip to content

Commit

Permalink
Project Roles/Applications
Browse files Browse the repository at this point in the history
WIP -- Roles for projects where users can apply for a position (role).
  • Loading branch information
kevin-dexter committed Jan 10, 2018
1 parent 749aa7e commit bf4b6bd
Show file tree
Hide file tree
Showing 10 changed files with 564 additions and 7 deletions.
259 changes: 255 additions & 4 deletions html-templates/projects/project.tpl

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions html-templates/projects/roleAdded.tpl
@@ -0,0 +1,12 @@
{extends designs/site.tpl}

{block title}{_ "Roles"} — {$dwoo.parent}{/block}

{block content}
{capture assign=project}{projectLink $Project}{/capture}

<div class="page-header">
<h1>Role Added</h1>
</div>
<p class="lead">{sprintf(_("%s has been added to %s"), $data->Role, $project)}</p>
{/block}
12 changes: 12 additions & 0 deletions html-templates/projects/roleApplicationAdded.tpl
@@ -0,0 +1,12 @@
{extends designs/site.tpl}

{block title}{_ "Roles"} &mdash; {$dwoo.parent}{/block}

{block content}
{capture assign=project}{projectLink $Project}{/capture}

<div class="page-header">
<h1>Application Added</h1>
</div>
<p class="lead">{sprintf(_(Your application for "%s has been added to %s"), $data->Role, $project)}</p>
{/block}
12 changes: 12 additions & 0 deletions html-templates/projects/roleModified.tpl
@@ -0,0 +1,12 @@
{extends designs/site.tpl}

{block title}{_ "Roles"} &mdash; {$dwoo.parent}{/block}

{block content}
{capture assign=project}{projectLink $Project}{/capture}

<div class="page-header">
<h1>Role Modified</h1>
</div>
<p class="lead">{sprintf(_("%s has been modified for %s"), $data->Role, $project)}</p>
{/block}
14 changes: 14 additions & 0 deletions html-templates/projects/roleRemoved.tpl
@@ -0,0 +1,14 @@
{extends designs/site.tpl}

{block title}Roles &mdash; {$dwoo.parent}{/block}

{block content}
<div class="row">
<div class="col-sm-8 col-sm-offset-2 col-md-6 col-md-offset-3">
<div class="page-header">
<h1>Role Removed</h1>
</div>
<p>{if $data && $data->Role}({$data->Role|escape}){/if} has been removed from {projectLink $Project}</p>
</div>
</div>
{/block}
26 changes: 24 additions & 2 deletions php-classes/Laddr/Project.php
Expand Up @@ -84,6 +84,27 @@ class Project extends \VersionedRecord
'linkForeign' => 'MemberID', 'linkForeign' => 'MemberID',
'indexField' => 'ID' 'indexField' => 'ID'
], ],
'Roles' => [
'type' => 'one-many',
'class' => ProjectRole::class,
'foreign' => 'ProjectID'
],
'OpenRoles' => [
'type' => 'one-many',
'class' => ProjectRole::class,
'foreign' => 'ProjectID',
'conditions' => [
'PersonID IS NULL'
]
],
'FilledRoles' => [
'type' => 'one-many',
'class' => ProjectRole::class,
'foreign' => 'ProjectID',
'conditions' => [
'PersonID IS NOT NULL'
]
],
'Memberships' => [ 'Memberships' => [
'type' => 'one-many', 'type' => 'one-many',
'class' => ProjectMember::class, 'class' => ProjectMember::class,
Expand Down Expand Up @@ -142,6 +163,7 @@ class Project extends \VersionedRecord
public static $dynamicFields = [ public static $dynamicFields = [
'Maintainer', 'Maintainer',
'Members', 'Members',
'Roles',
'Memberships', 'Memberships',
'Tags', 'Tags',
'TopicTags', 'TopicTags',
Expand Down Expand Up @@ -192,9 +214,9 @@ public function save($deep = true)
parent::save($deep); parent::save($deep);


if (!$this->Members) { if (!$this->Members) {
ProjectMember::create([ ProjectRole::create([
'ProjectID' => $this->ID, 'ProjectID' => $this->ID,
'MemberID' => $this->Maintainer->ID, 'PersonID' => $this->Maintainer->ID,
'Role' => 'Founder' // _("Founder") -- placeholder to make this string translatable, actual translation is done during rendering though 'Role' => 'Founder' // _("Founder") -- placeholder to make this string translatable, actual translation is done during rendering though
], true); ], true);
} }
Expand Down
46 changes: 46 additions & 0 deletions php-classes/Laddr/ProjectRole.php
@@ -0,0 +1,46 @@
<?php

namespace Laddr;

use Emergence\People\Person;


class ProjectRole extends \ActiveRecord
{
// ActiveRecord configuration
public static $tableName = 'project_roles'; // the name of this model's table

// controllers will use these values to figure out what templates to use
public static $singularNoun = 'project role'; // a singular noun for this model's object
public static $pluralNoun = 'project roles'; // a plural noun for this model's object

// gets combined with all the extended layers
public static $fields = [
'ProjectID' => 'uint',
'PersonID' => [
'type' =>'uint',
'default'=>null
],
'Role' => 'string',
'Description' => [
'type' =>'string',
'default'=>null
]
];

public static $relationships = [
'Project' => [
'type' => 'one-one',
'class' => Project::class
],
'Person' => [
'type' => 'one-one',
'class' => Person::class
]
];

public static $dynamicFields = [
'Project',
'Person'
];
}
106 changes: 106 additions & 0 deletions php-classes/Laddr/ProjectsRequestHandler.php
Expand Up @@ -18,6 +18,14 @@ class ProjectsRequestHandler extends \RecordsRequestHandler
public static function handleRecordRequest(\ActiveRecord $Project, $action = false) public static function handleRecordRequest(\ActiveRecord $Project, $action = false)
{ {
switch ($action ? $action : $action = static::shiftPath()) { switch ($action ? $action : $action = static::shiftPath()) {
case 'add-role':
return static::handleAddRoleRequest($Project);
case 'modify-role':
return static::handleModifyRoleRequest($Project);
case 'remove-role':
return static::handleRemoveRoleRequest($Project);
case 'add-application':
return static::handleAddRoleApplicationRequest($Project);
case 'add-member': case 'add-member':
return static::handleAddMemberRequest($Project); return static::handleAddMemberRequest($Project);
case 'remove-member': case 'remove-member':
Expand Down Expand Up @@ -84,6 +92,104 @@ public static function handleBrowseRequest($options = [], $conditions = [], $res
return parent::handleBrowseRequest($options, $conditions, $responseID, $responseData); return parent::handleBrowseRequest($options, $conditions, $responseID, $responseData);
} }


public static function handleAddRoleRequest(Project $Project)
{
$GLOBALS['Session']->requireAuthentication();

$Person = User::getByUsername($_POST['username']);

$recordData = [
'ProjectID' => $Project->ID,
'PersonID' => (!$Person)?null:$Person->ID
];

$ProjectRole = ProjectRole::create($recordData);

if (!empty($_POST['role'])) {
$ProjectRole->Role = $_POST['role'];
}

if (!empty($_POST['description'])) {
$ProjectRole->Description = $_POST['description'];
}

$ProjectRole->save();

return static::respond('roleAdded', [
'data' => $ProjectRole,
'Project' => $Project,
'Member' => $Person
]);
}

public static function handleModifyRoleRequest(Project $Project)
{
$GLOBALS['Session']->requireAuthentication();

$Person = User::getByUsername($_POST['username']);

$recordData = [
'ProjectID' => $Project->ID,
'PersonID' => (!$Person)?null:$Person->ID
];

$ProjectRole = ProjectRole::create($recordData);

if (!empty($_POST['role'])) {
$ProjectRole->Role = $_POST['role'];
}

if (!empty($_POST['description'])) {
$ProjectRole->Description = $_POST['description'];
}

$ProjectRole->save();

return static::respond('roleModified', [
'data' => $ProjectRole,
'Project' => $Project,
'Member' => $Person
]);
}

public static function handleAddRoleApplicationRequest(Project $Project){
$GLOBALS['Session']->requireAuthentication();

}

public static function handleRemoveRoleRequest(Project $Project)
{
$GLOBALS['Session']->requireAuthentication();

if (empty($_REQUEST['role_id'])) {
return static::throwError(_('Parameter "role_id" required'));
}

$ProjectRole = ProjectRole::getByWhere([
'ProjectID' => $Project->ID,
'ID' => $_REQUEST['role_id']
]);

if ($_SERVER['REQUEST_METHOD'] != 'POST') {
return static::respond('confirm', [
'question' => sprintf(
_('Are you sure you want to remove %s from %s?'),
htmlspecialchars($Role->Role),
htmlspecialchars($Project->Title)
)
]);
}

if ($ProjectRole) {
$ProjectRole->destroy();
}

return static::respond('roleRemoved', [
'data' => $ProjectRole,
'Project' => $Project
]);
}

public static function handleAddMemberRequest(Project $Project) public static function handleAddMemberRequest(Project $Project)
{ {
$GLOBALS['Session']->requireAuthentication(); $GLOBALS['Session']->requireAuthentication();
Expand Down
61 changes: 61 additions & 0 deletions php-classes/Laddr/RoleApplication.php
@@ -0,0 +1,61 @@
<?php

namespace Laddr;

use Emergence\People\Person;


class RoleApplication extends \ActiveRecord
{
// ActiveRecord configuration
public static $tableName = 'role_applications'; // the name of this model's table

// controllers will use these values to figure out what templates to use
public static $singularNoun = 'role application'; // a singular noun for this model's object
public static $pluralNoun = 'role applications'; // a plural noun for this model's object

// gets combined with all the extended layers
public static $fields = [
'ProjectID' => 'uint',
'PersonID' => 'uint',
'RoleID' => 'uint',
'Application' => 'string',
'Status' => [
'type' => 'enum',
'values' => [
'Pending',
'Accepted',
'Rejected'
],
'default' => 'Pending'
]
];

public static $relationships = [
'Project' => [
'type' => 'one-one',
'class' => Project::class
],
'Person' => [
'type' => 'one-one',
'class' => Person::class
],
'ProjectRole' => [
'type' => 'one-one',
'class' => ProjectRole::class
]
];

public static $indexes = [
'ProjectRoleApplication' => [
'fields' => ['ProjectID', 'PersonID', 'RoleID'],
'unique' => true
]
];

public static $dynamicFields = [
'Project',
'Person',
'Role'
];
}
23 changes: 22 additions & 1 deletion site-root/js/pages/project.js
Expand Up @@ -32,4 +32,25 @@
epicEditor.importFile('README', $textarea.val()); epicEditor.importFile('README', $textarea.val());
}); });
}); });
})(); })();

$( "#open_role_table" ).on( "click", "a[title^='Apply']", function( event ) {
$('#add-application').modal({show: 'true'});
$("#inputRoleId").val($( this ).attr( "data-role_id"));
});

$( "#open_role_table" ).on( "click", "a[title^='Edit Role']", function( event ){
$('#modify-role').modal({show: 'true'});
$("#inputRoleId").val($( this ).attr( "data-role_id"));
$("#inputRole").val($( this ).attr( "data-role_name"));
$("#inputRoleDescription").val($( this ).attr( "data-role_description"));
$("#inputUsername").val($( this ).attr( "data-role_person"));
});

$( "#role_table" ).on( "click", "a[title^='Edit Role']", function( event ) {
$('#modify-role').modal({show: 'true'});
$("#inputRoleId").val($( this ).attr( "data-role_id"));
$("#inputRole").val($( this ).attr( "data-role_name"));
$("#inputRoleDescription").val($( this ).attr( "data-role_description"));
$("#inputUsername").val($( this ).attr( "data-role_person"));
});

0 comments on commit bf4b6bd

Please sign in to comment.