Permalink
Browse files

Project Roles/Applications

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 bf4b6bd3c608fefb8965780b55ce69816b2a3d08

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -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}
@@ -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}
@@ -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}
@@ -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}
@@ -84,6 +84,27 @@ class Project extends \VersionedRecord
'linkForeign' => 'MemberID',
'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' => [
'type' => 'one-many',
'class' => ProjectMember::class,
@@ -142,6 +163,7 @@ class Project extends \VersionedRecord
public static $dynamicFields = [
'Maintainer',
'Members',
'Roles',
'Memberships',
'Tags',
'TopicTags',
@@ -192,9 +214,9 @@ public function save($deep = true)
parent::save($deep);
if (!$this->Members) {
ProjectMember::create([
ProjectRole::create([
'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
], true);
}
@@ -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'
];
}
@@ -18,6 +18,14 @@ class ProjectsRequestHandler extends \RecordsRequestHandler
public static function handleRecordRequest(\ActiveRecord $Project, $action = false)
{
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':
return static::handleAddMemberRequest($Project);
case 'remove-member':
@@ -84,6 +92,104 @@ public static function handleBrowseRequest($options = [], $conditions = [], $res
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)
{
$GLOBALS['Session']->requireAuthentication();
@@ -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'
];
}
@@ -32,4 +32,25 @@
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.