Created
March 29, 2017 15:01
-
-
Save ianrodrigues/3e37954fd141b586301f43159f2e2de2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
<?php | |
use Fluent\Node; | |
use Fluent\Fluent; | |
class BacklogWidget extends Node | |
{ | |
private $config; | |
private $cards; | |
private $controller; | |
private $key; | |
private $value; | |
public function __construct($cards) | |
{ | |
$this->cards = $cards; | |
$this->config = Config::get('view.kanban'); | |
} | |
public function controller($controller) | |
{ | |
$this->controller = $controller; | |
return $this; | |
} | |
public function key($key) | |
{ | |
$this->key = $key; | |
return $this; | |
} | |
public function value($value) | |
{ | |
$this->value = $value; | |
return $this; | |
} | |
public function make() | |
{ | |
$this->addChild( | |
Fluent::div() | |
->addClass('backlog') | |
->controller($this->controller) | |
->key($this->key) | |
->value($this->value) | |
->addChild( | |
Fluent::Row() | |
->paddingTop(10) | |
->paddingBottom(10) | |
->addChild( | |
Fluent::Col() | |
->colMd(12) | |
->addChild( | |
Fluent::FormField() | |
->colMd(3) | |
->colSm(3) | |
->colXs(3) | |
->marginBottom(0) | |
->label('Data inicial', 'backlog_filter_date_begin') | |
->field( | |
Fluent::DatePicker('date_begin')->value(date("d/m/Y", strtotime($this->data['date_begin']))) | |
) | |
) | |
->addChild( | |
Fluent::FormField() | |
->colMd(3) | |
->colSm(3) | |
->colXs(3) | |
->marginBottom(0) | |
->label('Data final', 'backlog_filter_date_end') | |
->field( | |
Fluent::DatePicker('date_end')->value(date("d/m/Y", strtotime($this->data['date_end']))) | |
) | |
) | |
->addChild( | |
Fluent::FormField() | |
->colMd(3) | |
->colSm(3) | |
->colXs(3) | |
->marginBottom(0) | |
->label('Pesquisar por', 'backlog_filter_text') | |
->field( | |
Fluent::InputText('filter_text')->setValue($this->data['filter_text']) | |
) | |
) | |
->addChild( | |
Fluent::InputText('job_id')->setType('hidden')->setValue($this->data['job']->id) | |
) | |
->addChild( | |
Fluent::button('btn_backlog_filter')->marginTop(20)->text('OK') | |
) | |
->addChild( | |
TaskHelper::createButton()->dataJobId($this->data['job']->id)->marginTop(21) | |
) | |
->addChild( | |
SprintHelper::createButton()->dataJobId($this->data['job']->id)->marginTop(21)->marginRight(10)->addStyle('background-color', Config::get('view.sprint.color')) | |
->addStyle('color', '#FFF') | |
) | |
) | |
) | |
->addChild( | |
$this->getStateColumns() | |
) | |
); | |
return $this; | |
} | |
private function getStateColumns() | |
{ | |
$columns = Fluent::div()->addClass('content-columns-state'); | |
$data = $this->data; | |
$sprintQuery = Sprint::fromJob($this->data['job']->id)->where(function ($query) use ($data) { | |
$query->whereBetween('date_start', array($data['date_begin'], $data['date_end'])); | |
$query->orWhereBetween('date_end', array($data['date_begin'], $data['date_end'])); | |
}); | |
if($this->data['filter_text']) | |
$sprintQuery = $sprintQuery->where('name', 'ilike', $this->data['filter_text'] . '%'); | |
$sprints = $sprintQuery->orderBy('date_start')->get(); | |
$tasksUnplanned = Task::withoutSprint($this->data['job']->id)->get(); | |
$columnsCount = count($sprints) + 1; | |
$columnContent = Fluent::ul('backlog-column-unplanned')->colMd(12)->addClass('sortable'); | |
foreach($tasksUnplanned as $card) | |
$columnContent->addChild( | |
Fluent::Html($card->card) | |
); | |
$columns->addChild( | |
Fluent::div() | |
->addStyle('width', (100 / $columnsCount).'%') | |
->addClass('columns-state') | |
->dataState('unplanned') | |
->dataText('Backlog') | |
->addChild( | |
Fluent::div() | |
->addStyle('border', '0px solid #FFF') | |
->addStyle('border-left-width', '1px') | |
->addStyle('border-left-color', '#CCC') | |
->addStyle('border-bottom-width', '8px') | |
->addStyle('border-bottom-color', 'gray') | |
->addChild( | |
Fluent::h2() | |
->text('Backlog') | |
->addStyle('background-image', 'linear-gradient(to bottom,#F9F9F9 100%,#F9F9F9 100%)') | |
->addChild( | |
Fluent::badge() | |
->marginLeft(5) | |
->addStyle('background', 'gray') | |
->setValue(count($columnContent->getChilds())) | |
) | |
) | |
) | |
->addChild($columnContent) | |
); | |
foreach($sprints as $sprint) { | |
$columnContent = Fluent::ul() | |
->colMd(12) | |
->addClass('sprint') | |
->dataId($sprint->id) | |
->addClass('sortable'); | |
foreach($sprint->tasks()->orderBy('status')->get() as $card) | |
$columnContent->addChild( | |
Fluent::Html($card->card) | |
); | |
$columns->addChild( | |
Fluent::div() | |
->addStyle('width', (100 / $columnsCount).'%') | |
->addClass('columns-state') | |
->dataState($sprint->id) | |
->dataText($sprint->name) | |
->addChild( | |
Fluent::div() | |
->addStyle('border', '0px solid #FFF') | |
->addStyle('border-left-width', '1px') | |
->addStyle('border-left-color', '#CCC') | |
->addStyle('border-bottom-width', '8px') | |
->addStyle('border-bottom-color', 'gray') | |
->addChild( | |
Fluent::h2() | |
->addStyle('background-image', 'linear-gradient(to bottom,#F9F9F9 100%,#F9F9F9 100%)') | |
->text($sprint->name) | |
->addChild( | |
Fluent::badge() | |
->marginLeft(5) | |
->addStyle('background', 'gray') | |
->setValue(count($columnContent->getChilds())) | |
) | |
) | |
->addChild( | |
Fluent::h5() | |
->text(DateTime::createFromFormat('Y-m-d H:i:s', $sprint->date_start)->format('d/m/Y') . ' a ' . DateTime::createFromFormat('Y-m-d H:i:s', $sprint->date_end)->format('d/m/Y') ) | |
) | |
) | |
->addChild($columnContent) | |
); | |
} | |
return $columns; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment