-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
admin controller to edit, delete projects and missions
- Loading branch information
appliedrd
committed
Aug 4, 2016
1 parent
19f7a8c
commit dd6f0b2
Showing
12 changed files
with
990 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
<?php | ||
namespace App\Controller; | ||
|
||
use App\Controller\AppController; | ||
use Cake\ORM\TableRegistry; | ||
|
||
/** | ||
* Projects Controller | ||
* | ||
* @property \App\Model\Table\ProjectsTable $Projects | ||
*/ | ||
class AdminsController extends AppController | ||
{ | ||
public function initialize() | ||
{ | ||
parent::initialize(); | ||
$this->Projects = TableRegistry::get('Projects'); | ||
$this->Users = TableRegistry::get('Users'); | ||
//$this->loadComponent('RequestHandler'); | ||
} | ||
public function isAuthorized($user) | ||
{ | ||
$user = $this->Users->findById($user['id'])->first(); | ||
if ($user && ($user->hasRoleName(['Administrator'])) | ||
) { | ||
return true; | ||
} | ||
} | ||
|
||
/** | ||
* Index method | ||
* | ||
* @return \Cake\Network\Response|null | ||
*/ | ||
public function index() | ||
{ | ||
$this->paginate = [ | ||
'limit' => 1000, | ||
'order' => ['Projects.name' => 'asc'], | ||
'contain' => ['Organizations', 'Missions','Missions.Users','Missions.Professors'] | ||
]; | ||
$projects = $this->paginate($this->Projects); | ||
$this->set(compact('projects')); | ||
$this->set('_serialize', ['projects']); | ||
} | ||
|
||
/** | ||
* View method | ||
* | ||
* @param string|null $id Project id. | ||
* @return \Cake\Network\Response|null | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function view($id = null) | ||
{ | ||
$project = $this->Projects->get($id, [ | ||
'contain' => ['Organizations', 'Contributors', 'Mentors', 'Missions', 'Applications'] | ||
]); | ||
|
||
$this->set('project', $project); | ||
$this->set('_serialize', ['project']); | ||
} | ||
|
||
/** | ||
* Add method | ||
* | ||
* @return \Cake\Network\Response|void Redirects on successful add, renders view otherwise. | ||
*/ | ||
public function add() | ||
{ | ||
$project = $this->Projects->newEntity(); | ||
if ($this->request->is('post')) { | ||
$project = $this->Projects->patchEntity($project, $this->request->data); | ||
if ($this->Projects->save($project)) { | ||
$this->Flash->success(__('The project has been saved.')); | ||
return $this->redirect(['action' => 'index']); | ||
} else { | ||
$this->Flash->error(__('The project could not be saved. Please, try again.')); | ||
} | ||
} | ||
$organizations = $this->Projects->Organizations->find('list', ['limit' => 200]); | ||
$contributors = $this->Projects->Contributors->find('list', ['limit' => 200]); | ||
$mentors = $this->Projects->Mentors->find('list', ['limit' => 200]); | ||
$this->set(compact('project', 'organizations', 'contributors', 'mentors')); | ||
$this->set('_serialize', ['project']); | ||
} | ||
|
||
/** | ||
* Edit method | ||
* | ||
* @param string|null $id Project id. | ||
* @return \Cake\Network\Response|void Redirects on successful edit, renders view otherwise. | ||
* @throws \Cake\Network\Exception\NotFoundException When record not found. | ||
*/ | ||
public function edit($id = null) | ||
{ | ||
$project = $this->Projects->get($id, [ | ||
'contain' => ['Organizations', 'Contributors', 'Mentors'] | ||
]); | ||
if ($this->request->is(['patch', 'post', 'put'])) { | ||
$project = $this->Projects->patchEntity($project, $this->request->data); | ||
if ($this->Projects->save($project)) { | ||
$this->Flash->success(__('The project has been saved.')); | ||
return $this->redirect(['action' => 'index']); | ||
} else { | ||
$this->Flash->error(__('The project could not be saved. Please, try again.')); | ||
} | ||
} | ||
$organizations = $this->Projects->Organizations->find('list', ['limit' => 200]); | ||
$contributors = $this->Projects->Contributors->find('list', ['limit' => 200]); | ||
$mentors = $this->Projects->Mentors->find('list', ['limit' => 200]); | ||
$this->set(compact('project', 'organizations', 'contributors', 'mentors')); | ||
$this->set('_serialize', ['project']); | ||
} | ||
|
||
/** | ||
* Delete method | ||
* | ||
* @param string|null $id Project id. | ||
* @return \Cake\Network\Response|null Redirects to index. | ||
* @throws \Cake\Datasource\Exception\RecordNotFoundException When record not found. | ||
*/ | ||
public function delete($id = null) | ||
{ | ||
$this->request->allowMethod(['post', 'delete']); | ||
$project = $this->Projects->get($id); | ||
if ($this->Projects->delete($project)) { | ||
$this->Flash->success(__('The project has been deleted.')); | ||
} else { | ||
$this->Flash->error(__('The project could not be deleted. Please, try again.')); | ||
} | ||
return $this->redirect(['action' => 'index']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<nav class="large-3 medium-4 columns" id="actions-sidebar"> | ||
<ul class="side-nav"> | ||
<li class="heading"><?= __('Actions') ?></li> | ||
<li><?= $this->Html->link(__('List Projects'), ['action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('List Missions'), ['controller' => 'Missions', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Mission'), ['controller' => 'Missions', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Applications'), ['controller' => 'Applications', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Application'), ['controller' => 'Applications', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Organizations'), ['controller' => 'Organizations', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Organization'), ['controller' => 'Organizations', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Contributors'), ['controller' => 'Users', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Contributor'), ['controller' => 'Users', 'action' => 'add']) ?></li> | ||
</ul> | ||
</nav> | ||
<div class="projects form large-9 medium-8 columns content"> | ||
<?= $this->Form->create($project) ?> | ||
<fieldset> | ||
<legend><?= __('Add Project') ?></legend> | ||
<?php | ||
echo $this->Form->input('name'); | ||
echo $this->Form->input('link'); | ||
echo $this->Form->input('description'); | ||
echo $this->Form->input('accepted'); | ||
echo $this->Form->input('archived'); | ||
echo $this->Form->input('repository_link'); | ||
echo $this->Form->input('organizations._ids', ['options' => $organizations]); | ||
echo $this->Form->input('contributors._ids', ['options' => $contributors]); | ||
echo $this->Form->input('mentors._ids', ['options' => $mentors]); | ||
?> | ||
</fieldset> | ||
<?= $this->Form->button(__('Submit')) ?> | ||
<?= $this->Form->end() ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<div class="row"> | ||
<?= $this->cell('Sidebar::project', [$project->id]); ?> | ||
|
||
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12"> | ||
<?= $this->Form->create($application); ?> | ||
<fieldset> | ||
<legend><?= __('Apply on this project') ?></legend> | ||
<?php | ||
echo $this->Form->input('presentation', ['type' => 'textarea']); | ||
echo $this->Form->input('type_application_id', ['options' => $typeApplications, 'type' => 'select']); | ||
echo $this->Form->input('weeklyHours', ['min' => '0']); | ||
echo $this->Form->input('startDate'); | ||
echo $this->Form->input('endDate'); | ||
?> | ||
</fieldset> | ||
<?= $this->Form->button(__('Submit'), ['class' => 'btn-success']) ?> | ||
<?= $this->Form->button(__('Cancel'), [ | ||
'type' => 'button', | ||
'class' => 'btn btn-default', | ||
'onclick' => 'location.href=\'' . $this->url->build([ | ||
'controller' => 'Projects', | ||
'action' => 'view', | ||
$project->id | ||
]) . '\'' | ||
]); ?> | ||
<?= $this->Form->end() ?> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<nav class="large-3 medium-4 columns" id="actions-sidebar"> | ||
<ul class="side-nav"> | ||
<li class="heading"><?= __('Actions') ?></li> | ||
<li><?= $this->Form->postLink( | ||
__('Delete'), | ||
['action' => 'delete', $project->id], | ||
['confirm' => __('Are you sure you want to delete # {0}?', $project->id)] | ||
) | ||
?></li> | ||
<li><?= $this->Html->link(__('List Projects'), ['action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('List Missions'), ['controller' => 'Missions', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Mission'), ['controller' => 'Missions', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Applications'), ['controller' => 'Applications', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Application'), ['controller' => 'Applications', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Organizations'), ['controller' => 'Organizations', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Organization'), ['controller' => 'Organizations', 'action' => 'add']) ?></li> | ||
<li><?= $this->Html->link(__('List Contributors'), ['controller' => 'Users', 'action' => 'index']) ?></li> | ||
<li><?= $this->Html->link(__('New Contributor'), ['controller' => 'Users', 'action' => 'add']) ?></li> | ||
</ul> | ||
</nav> | ||
<div class="projects form large-9 medium-8 columns content"> | ||
<?= $this->Form->create($project) ?> | ||
<fieldset> | ||
<legend><?= __('Edit Project') ?></legend> | ||
<?php | ||
echo $this->Form->input('name'); | ||
echo $this->Form->input('link'); | ||
echo $this->Form->input('description'); | ||
echo $this->Form->input('accepted'); | ||
echo $this->Form->input('archived'); | ||
echo $this->Form->input('repository_link'); | ||
echo $this->Form->input('organizations._ids', ['options' => $organizations]); | ||
echo $this->Form->input('contributors._ids', ['options' => $contributors]); | ||
echo $this->Form->input('mentors._ids', ['options' => $mentors]); | ||
?> | ||
</fieldset> | ||
<?= $this->Form->button(__('Submit')) ?> | ||
<?= $this->Form->end() ?> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<div class="row"> | ||
<?= $this->cell('Sidebar::project', [$project->id]); ?> | ||
<div class="col-lg-9 col-md-9 col-sm-9 col-xs-12"> | ||
<div class="row"> | ||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> | ||
<h1 class="page-header"><?=__('Edit mentors'); ?></h1> | ||
<?php | ||
$this->Html->addCrumb(__('Home'), '/'); | ||
$this->Html->addCrumb(__('Projects'), '/Projects'); | ||
$this->Html->addCrumb($project->getName(), '/projects/view/' . $project->id); | ||
$this->Html->addCrumb(__('Edit mentors')); | ||
|
||
echo $this->Html->getCrumbList(); ?> | ||
</div> | ||
</div> | ||
<div class="row"> | ||
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12"> | ||
<div class="panel panel-default"> | ||
<div class="panel-body"> | ||
<h3 class="header-title"><?= __('Edit mentors') ?></h3> | ||
<?= $this->Form->create($project); ?> | ||
<fieldset> | ||
<select multiple id="users" name="users[]"> | ||
<?php foreach ($members as $member) { | ||
foreach ($mentors as $mentor) { | ||
if ($mentor->getId() === $member->getId()) { | ||
$selected = true; | ||
break; | ||
} else | ||
$selected = false; | ||
} | ||
|
||
if ($selected) { ?> | ||
<option value="<?= $member['id'] ?>" | ||
selected><?= '(' . $member['username'] . ') ' . $member['firstName'] . ' ' . $member['lastName'] ?></option> | ||
<?php } else { ?> | ||
<option | ||
value="<?= $member['id'] ?>"><?= '(' . $member['username'] . ') ' . $member['firstName'] . ' ' . $member['lastName'] ?></option> | ||
<?php } | ||
} ?> | ||
</select> | ||
</fieldset> | ||
<br> | ||
<?= $this->Form->button(__('Submit'), ['class' => 'btn-info']) ?> | ||
<?= $this->Form->button(__('Cancel'), [ | ||
'type' => 'button', | ||
'class' => 'btn btn-default', | ||
'onclick' => 'location.href=\'' . $this->url->build([ | ||
'controller' => 'Projects', | ||
'action' => 'view', | ||
$project->id | ||
]) . '\'' | ||
]); ?> | ||
<?= $this->Form->end() ?> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<?= $this->Html->script(['projects/edit-mentor.js', 'duallistbox/dual-list-box.min.js', 'initial.min'], ['block' => 'scriptBottom']); ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<? //echo phpinfo(); ?> | ||
<div class="projects index large-9 medium-8 columns content"> | ||
<h3><?= __('Administer Projects') ?></h3> | ||
<div class="table-responsive"> | ||
<table id="projects" class="table table-striped table-bordered dataTable"> | ||
|
||
<thead> | ||
<tr> | ||
<th><?= $this->Paginator->sort('id') ?></th> | ||
<th>Org</th> | ||
<th><?= $this->Paginator->sort('name') ?></th> | ||
<th><?= $this->Paginator->sort('created') ?></th> | ||
<th class="actions"><?= __('Actions') ?></th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<?php foreach ($projects as $project): ?> | ||
<tr> | ||
<td><?= $this->Number->format($project->id) ?></td> | ||
<td><? if (isset($project->organizations[0]['name'])) { | ||
echo $project->organizations[0]['name']; }?></td> | ||
<td><?= h($project->name) ?></td> | ||
<td><?= h($project->created) ?></td> | ||
<td class="actions"> | ||
<?= $this->Html->link('<i class="fa fa-eye"></i>', | ||
['action' => 'view', $project->id],['escape' => false]) ?> | ||
<?= $this->Form->postLink('<i class="fa fa-trash"></i>', | ||
['action' => 'delete', $project->id], | ||
['escape' => false], | ||
['confirm' => __('Are you sure you want to delete # {0}? and all it missions?', | ||
$project->id)] | ||
) ?> | ||
<?= $this->Html->link(__('missions'), ['controller' => 'Missions','action' => 'projectindex', $project->id]) ?> | ||
</td> | ||
</tr> | ||
<?php endforeach; ?> | ||
</tbody> | ||
</table> | ||
</div> | ||
<div class="paginator"> | ||
<ul class="pagination"> | ||
<?= $this->Paginator->prev('< ' . __('previous')) ?> | ||
<?= $this->Paginator->numbers() ?> | ||
<?= $this->Paginator->next(__('next') . ' >') ?> | ||
</ul> | ||
<p><?= $this->Paginator->counter() ?></p> | ||
</div> | ||
</div> |
Oops, something went wrong.