Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rate our service #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 49 additions & 1 deletion npm-package/css/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -177,4 +177,52 @@ textarea {

.select2-ctl-dropdown li {
font-size: .9rem !important;
}
}

/* rating */

.rating {
display: flex;
flex-direction: row-reverse;
justify-content: center
}

.rating>input {
display: none
}

.rating>label {
position: relative;
width: 1em;
font-size: 30px;
font-weight: 300;
color: #FFD600;
cursor: pointer
}

.rating>span {
position: relative;
width: 1em;
font-size: 30px;
font-weight: 300;
color: #FFD600;
}

.rating>label::before {
content: "\2605";
position: absolute;
opacity: 0
}

.rating>label:hover:before,
.rating>label:hover~label:before {
opacity: 1 !important
}

.rating>input:checked~label:before {
opacity: 1
}

.rating:hover>input:checked~label:before {
opacity: 0.4
}
50 changes: 41 additions & 9 deletions src/Serwisant/SerwisantCp/Actions/Repairs.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,14 @@

use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairsFilter;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairsFilterType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairTransportType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairsSort;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairInput;
use Serwisant\SerwisantApi\Types\SchemaCustomer\AddressUpdateInput;
use Serwisant\SerwisantApi\Types\SchemaCustomer\PrintType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairTransportType;

use Serwisant\SerwisantApi\Types\SchemaCustomer\RatingSubjectType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RatingInput;

class Repairs extends Action
{
Expand Down Expand Up @@ -43,19 +46,17 @@ public function index()
return $this->renderPage('repairs.html.twig', $variables);
}

public function show($id)
public function show($id, $rating_errors = [])
{
$this->checkModuleActive();

$filter = new RepairsFilter(['type' => RepairsFilterType::ID, 'ID' => $id]);
$result = $this->apiCustomer()->customerQuery()->repairs(1, null, $filter, null, ['single' => true]);
if (count($result->items) !== 1) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}
$repair = $this->fetchRepair($id);

$variables = [
'repair' => $result->items[0],
'pageTitle' => $result->items[0]->rma,
'repair' => $repair,
'pageTitle' => $repair->rma,
'form_params' => $this->request->request,
'rating_errors' => $rating_errors,
];

return $this->renderPage('repair.html.twig', $variables);
Expand Down Expand Up @@ -212,6 +213,37 @@ public function create()
}
}

public function rate($id)
{
$this->checkModuleActive();

$repair = $this->fetchRepair($id);

if (false === $repair->isRateable) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}

$rating_input = new RatingInput($this->request->get('rating', []));

$result = $this->apiCustomer()->customerMutation()->setRating($id, RatingSubjectType::REPAIR, $rating_input);

if ($result->errors) {
return $this->show($id, $result->errors);
} else {
return $this->redirectTo(['repair', ['id' => $id]]);
}
}

private function fetchRepair($id)
{
$filter = new RepairsFilter(['type' => RepairsFilterType::ID, 'ID' => $id]);
$result = $this->apiCustomer()->customerQuery()->repairs(1, null, $filter, null, ['single' => true]);
if (count($result->items) !== 1) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}
return $result->items[0];
}

private function checkModuleActive()
{
$this->checkPanelActive();
Expand Down
49 changes: 40 additions & 9 deletions src/Serwisant/SerwisantCp/Actions/Tickets.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
use Serwisant\SerwisantCp\ExceptionNotFound;

use Serwisant\SerwisantApi\Types\SchemaCustomer\AddressUpdateInput;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RepairsFilterType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\TicketsFilter;
use Serwisant\SerwisantApi\Types\SchemaCustomer\TicketsFilterType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\TicketsSort;
use Serwisant\SerwisantApi\Types\SchemaCustomer\TicketInput;
use Serwisant\SerwisantApi\Types\SchemaCustomer\PrintType;

use Serwisant\SerwisantApi\Types\SchemaCustomer\RatingSubjectType;
use Serwisant\SerwisantApi\Types\SchemaCustomer\RatingInput;

class Tickets extends Action
{
use Traits\Devices;
Expand All @@ -39,19 +41,17 @@ public function index()
return $this->renderPage('tickets.html.twig', $variables);
}

public function show($id)
public function show($id, $rating_errors = [])
{
$this->checkModuleActive();

$filter = new TicketsFilter(['type' => RepairsFilterType::ID, 'ID' => $id]);
$result = $this->apiCustomer()->customerQuery()->tickets(1, null, $filter, null, ['single' => true]);
if (count($result->items) !== 1) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}
$ticket = $this->fetchTicket($id);

$variables = [
'ticket' => $result->items[0],
'pageTitle' => $result->items[0]->number,
'ticket' => $ticket,
'pageTitle' => $ticket->number,
'form_params' => $this->request->request,
'rating_errors' => $rating_errors,
];

return $this->renderPage('ticket.html.twig', $variables);
Expand Down Expand Up @@ -167,6 +167,37 @@ public function create()
}
}

public function rate($id)
{
$this->checkModuleActive();

$ticket = $this->fetchTicket($id);

if (false === $ticket->isRateable) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}

$rating_input = new RatingInput($this->request->get('rating', []));

$result = $this->apiCustomer()->customerMutation()->setRating($id, RatingSubjectType::TICKET, $rating_input);

if ($result->errors) {
return $this->show($id, $result->errors);
} else {
return $this->redirectTo(['ticket', ['id' => $id]]);
}
}

private function fetchTicket($id)
{
$filter = new TicketsFilter(['type' => TicketsFilterType::ID, 'ID' => $id]);
$result = $this->apiCustomer()->customerQuery()->tickets(1, null, $filter, null, ['single' => true]);
if (count($result->items) !== 1) {
throw new ExceptionNotFound(__CLASS__, __LINE__);
}
return $result->items[0];
}

private function checkModuleActive()
{
$this->checkPanelActive();
Expand Down
Loading