Skip to content

Commit

Permalink
Добавляет создание новых задач и показ этих задач внутри сделки
Browse files Browse the repository at this point in the history
  • Loading branch information
magniacarpa committed Nov 27, 2020
1 parent ad3799c commit 606c8ec
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 58 deletions.
2 changes: 0 additions & 2 deletions frontend/controllers/ContactsController.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<?php
namespace frontend\controllers;
use common\services\GmailClient;
use common\services\GoogleAuthClientFactory;
use frontend\models\Contact;
use Yii;

Expand Down
1 change: 0 additions & 1 deletion frontend/controllers/DealsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace frontend\controllers;

use frontend\behaviors\FeedBehavior;
use frontend\models\Deal;
use frontend\models\DealStatus;
use frontend\models\Feed;
Expand Down
6 changes: 4 additions & 2 deletions frontend/controllers/TableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class TableController extends SecuredController
* @var ActiveRecord
*/
protected $entity;

protected $alias;

protected $redirectAfterSaveUrl = null;

public function actionCreate()
{
$model = $this->entity;
Expand All @@ -35,8 +36,9 @@ public function actionCreate()

if ($model->save()) {
Yii::$app->getSession()->setFlash($this->alias . '_create');
$redirectUrl = $this->redirectAfterSaveUrl ?: [$this->alias . '/index'];

return $this->redirect([$this->alias . '/index']);
return $this->redirect($redirectUrl);
}
}
}
Expand Down
13 changes: 10 additions & 3 deletions frontend/controllers/TasksController.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,19 @@
namespace frontend\controllers;


use frontend\models\Deal;
use frontend\models\Task;

class TasksController extends TableController
{

public function actionCreate()
public function init()
{
return parent::actionCreate(); // TODO: Change the autogenerated stub
parent::init();

$this->entity = new Task();
$this->alias = 'tasks';
$this->redirectAfterSaveUrl = \Yii::$app->request->getReferrer();
}


}
6 changes: 6 additions & 0 deletions frontend/models/Deal.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
* @property string $dt_add
*
* @property DealStatus $status
* @property Task[] $tasks
*/
class Deal extends ActiveRecord
{
Expand Down Expand Up @@ -131,6 +132,11 @@ public function getNotes()
return $this->hasMany(Note::class, ['deal_id' => 'id']);
}

public function getTasks()
{
return $this->hasMany(Task::class, ['deal_id' => 'id']);
}

public function getFeed()
{
return $this->hasMany(Feed::class, ['deal_id' => 'id'])->orderBy('dt_add ASC');
Expand Down
6 changes: 3 additions & 3 deletions frontend/models/Task.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace frontend\models;

use Yii;
use yii\db\ActiveRecord;

/**
* This is the model class for table "task".
Expand All @@ -19,7 +19,7 @@
* @property User $executor
* @property TaskType $type
*/
class Task extends \yii\db\ActiveRecord
class Task extends ActiveRecord
{
/**
* {@inheritdoc}
Expand All @@ -35,7 +35,7 @@ public static function tableName()
public function rules()
{
return [
[['description', 'executor_id', 'type_id', 'deal_id'], 'required'],
[['description', 'executor_id', 'type_id', 'deal_id'], 'required', 'on' => 'insert'],
[['description'], 'string'],
[['executor_id', 'type_id', 'deal_id'], 'integer'],
[['due_date', 'dt_add'], 'safe'],
Expand Down
68 changes: 52 additions & 16 deletions frontend/views/deals/view.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use frontend\models\Contact;
use frontend\models\Deal;
use frontend\models\Note;
use frontend\models\Task;
use frontend\models\User;
use frontend\widgets\FeedItem;
use yii\data\ActiveDataProvider;
Expand Down Expand Up @@ -66,6 +67,9 @@
<li class="js-tab-control active">
<button type="button">Основное</button>
</li>
<li class="js-tab-control">
<button type="button">Задачи</button>
</li>
<li class="js-tab-control">
<button type="button">Участники</button>
</li>
Expand Down Expand Up @@ -122,30 +126,62 @@
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
<div class="deal-card__tab tab js-tab">
<div class="members">
<?php foreach ($deal->getAllParticipants() as $person): ?>
<div class="contact members__contact">
<div class="avatar avatar--contact contact__avatar"><span>O</span></div>
<div class="contact__inner"><a class="contact__name" href="#"><?=$person->getPersonName(); ?></a>
<p class="contact__row contact__row--company"><span
class="contact__title">Компания:</span><a class="contact__value link"
href="#"><?=$person->getPersonCompany(); ?></a></p>
<p class="contact__row contact__row--position"><span
class="contact__title">Должность:</span>
<span class="contact__value"><?=$person->getPersonPosition(); ?></span>
</p>
</div>
<div class="deal-card__tab tab js-tab">
<div class="task"><a class="button button--shadow js-create-task task__button" href="#"><span>Новая задача</span></a>
<?php if ($deal->tasks): ?>
<table class="task__table" cellspacing="0">
<tr>
<th>
<p>Дата создания</p>
</th>
<th>
<p>Тип</p>
</th>
<th>
<p>Исполнитель</p>
</th>
<th>
<p>Срок</p>
</th>
</tr>
<?php foreach ($deal->tasks as $task): ?>
<tr>
<td><p><?=$task->dt_add;?></p></td>
<td><p><?=$task->type->name; ?></p></td>
<td><p><?=$task->executor->name; ?></p></td>
<td><p><?=$task->due_date; ?></p></td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
</div>
</div>
<div class="deal-card__tab tab js-tab">
<div class="members">
<?php foreach ($deal->getAllParticipants() as $person): ?>
<div class="contact members__contact">
<div class="avatar avatar--contact contact__avatar"><span>O</span></div>
<div class="contact__inner"><a class="contact__name" href="#"><?=$person->getPersonName(); ?></a>
<p class="contact__row contact__row--company"><span
class="contact__title">Компания:</span><a class="contact__value link"
href="#"><?=$person->getPersonCompany(); ?></a></p>
<p class="contact__row contact__row--position"><span
class="contact__title">Должность:</span>
<span class="contact__value"><?=$person->getPersonPosition(); ?></span>
</p>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
</div>
</div>
<div class="deal-section__log">
<div class="deal-log">
<?=$this->render('//partials/_task_create', ['model' => new Task, 'deal_id' => $deal->id]); ?>

<p class="header-3 deal-log__header">События</p>
<ul class="deal-log__list">
<?php foreach ($deal->getFeedItems() as $feedItem): ?>
Expand Down
66 changes: 35 additions & 31 deletions frontend/views/partials/_task_create.php
Original file line number Diff line number Diff line change
@@ -1,43 +1,47 @@
<?php

use frontend\models\Task;
use frontend\models\TaskType;
use frontend\models\User;
use yii\helpers\ArrayHelper;
use yii\widgets\ActiveForm;

/**
* @var Task $model
* @var integer $deal_id
*/
?>

<div class="task-widget"><a class="button button--shadow task-widget__button js-create-task" href="#"><span>Новая задача</span></a>
<div class="task-widget">
<a class="button button--shadow task-widget__button js-create-task" href="#"><span>Новая задача</span></a>
<div class="alert task-widget__container js-task-widget">
<button class="alert__close button button--icon task-widget__close-button" type="button">
<svg width="24" height="24">
<use xlink:href="img/sprite.svg#x-circle"></use>
<use xlink:href="/img/sprite.svg#x-circle"></use>
</svg>
</button>
<div class="alert__content"><textarea class="textarea task-widget__textarea" rows="1"
placeholder="Описание"></textarea>
<form class="task-widget__form deal-form" method="POST">
<div class="task-widget__type"><select class="select">
<option value="0" placeholder="placeholder">Тип задачи</option>
<option value="1">Разработка</option>
<option value="2">Маркетинг</option>
<option value="3">Дизайн</option>
<option value="4">Аналитика</option>
<option value="5">Копирайтинг</option>
</select></div>
<div class="task-widget__executor"><select class="select">
<option value="0" placeholder="placeholder">Исполнитель</option>
<option value="1">Олег Иванов</option>
<option value="2">Анна Михайлова</option>
<option value="3">Алиса Федосеева</option>
<option value="4">Влад Климов</option>
<option value="5">Михайл Кочетков</option>
<option value="6">Юрий Пономарев</option>
<option value="7">Яна Светлова</option>
</select></div>
<div class="task-widget__date-wrapper"><input
class="task-widget__input task-widget__input--date deal-form__field--date deal-form__field js-resizable"
type="text" readonly="readonly" placeholder="Срок"/>
<div class="task-widget__calendar-container"></div>
</div>
<button class="task-widget__button link" type="submit"><span>Добавить</span></button>
</form>
<div class="alert__content">
<?php $form = ActiveForm::begin(['method' => 'post', 'action' => ['tasks/create'],
'fieldConfig' => ['template' => '{input}']]); ?>
<?=$form->field($model, 'description')
->textarea(['class' => 'textarea task-widget__textarea', 'rows' => 1, 'placeholder' => 'Описание']); ?>

<div class="task-widget__form deal-form">
<?=$form->field($model, 'deal_id')->hiddenInput(['value' => $deal_id]); ?>
<?=$form->field($model, 'type_id', ['options' => ['class' => 'task-widget__type']])
->dropDownList(ArrayHelper::map(TaskType::find()->all(), 'id', 'name'), ['class' => 'select', 'prompt' => 'Тип']); ?>

<?=$form->field($model, 'executor_id', ['options' => ['class' => 'task-widget__executor']])
->dropDownList(ArrayHelper::map(User::find()->all(), 'id', 'name'), ['class' => 'select', 'prompt' => 'Исполнитель']); ?>

<div class="task-widget__date-wrapper">
<?=$form->field($model, 'due_date')
->input('text', ['class' => 'task-widget__input task-widget__input--date deal-form__field--date deal-form__field js-resizable', 'placeholder' => 'Срок']); ?>
<div class="task-widget__calendar-container"></div>
</div>
<button class="task-widget__button link" type="submit"><span>Добавить</span></button>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>

0 comments on commit 606c8ec

Please sign in to comment.