mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-14 17:10:53 +00:00
Add form
This commit is contained in:
parent
69f81b9165
commit
b76dbb6df6
11 changed files with 61 additions and 25 deletions
|
|
@ -1,5 +1,5 @@
|
|||
@managing_administrators
|
||||
Feature: Remove an administrator avatar
|
||||
Feature: Removing an administrator avatar
|
||||
In order to properly identify the account
|
||||
As an Administrator
|
||||
I want to remove an administrator avatar of an account
|
||||
|
|
@ -9,7 +9,7 @@ Feature: Remove an administrator avatar
|
|||
And this administrator has the "troll.jpg" image as avatar
|
||||
|
||||
@ui
|
||||
Scenario: Remove an administrator avatar
|
||||
Scenario: Removing an administrator avatar
|
||||
Given I am editing my details
|
||||
When I remove the avatar image
|
||||
And I should not see the avatar image in the top bar next to my name
|
||||
And I should not see the "troll.jpg" avatar image in the top bar next to my name
|
||||
|
|
@ -344,11 +344,12 @@ final class ManagingAdministratorsContext implements Context
|
|||
|
||||
/**
|
||||
* @Given /^I should not see the "([^"]*)" avatar image in the top bar next to my name$/
|
||||
* @Given /^I should not see the avatar image in the top bar next to my name$/
|
||||
*/
|
||||
public function iShouldNotSeeTheAvatarImageInTheTopBarNextToMyName(string $avatar): void
|
||||
{
|
||||
Assert::true(!$this->topBarElement->hasAvatarInMainBar($avatar));
|
||||
$avatarPath = $this->sharedStorage->get($avatar);
|
||||
|
||||
Assert::true(!$this->topBarElement->hasAvatarInMainBar($avatarPath));
|
||||
Assert::true($this->topBarElement->hasDefaultAvatarInMainBar());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -19,17 +19,22 @@ final class TopBarElement extends Element implements TopBarElementInterface
|
|||
{
|
||||
public function hasAvatarInMainBar(string $avatarPath): bool
|
||||
{
|
||||
$image = $this->getDocument()->find('css', 'img.ui.avatar.image');
|
||||
|
||||
if (null === $image) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return strpos($image->getAttribute('src'), $avatarPath) !== false;
|
||||
return strpos($this->getAvatarImagePath(), $avatarPath) !== false;
|
||||
}
|
||||
|
||||
public function hasDefaultAvatarInMainBar(): bool
|
||||
{
|
||||
return strpos($this->getAvatarImagePath(), '//placehold.it/50x50') !== false;
|
||||
}
|
||||
|
||||
private function getAvatarImagePath(): string
|
||||
{
|
||||
$image = $this->getDocument()->find('css', 'img.ui.avatar.image');
|
||||
|
||||
if (null === $image) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return $image->getAttribute('src');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,6 +53,11 @@ class UpdatePage extends BaseUpdatePage implements UpdatePageInterface
|
|||
return strpos($srcPath, $avatarPath) !== false;
|
||||
}
|
||||
|
||||
public function removeAvatar(): void
|
||||
{
|
||||
$this->getDocument()->find('css', '#delete-button')->click();
|
||||
}
|
||||
|
||||
protected function getDefinedElements(): array
|
||||
{
|
||||
return array_merge(parent::getDefinedElements(), [
|
||||
|
|
|
|||
|
|
@ -28,4 +28,6 @@ interface UpdatePageInterface extends BaseUpdatePageInterface
|
|||
public function changeLocale(string $localeCode): void;
|
||||
|
||||
public function hasAvatar(string $avatarPath): bool;
|
||||
|
||||
public function removeAvatar(): void;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,19 +13,18 @@ declare(strict_types=1);
|
|||
|
||||
namespace Sylius\Bundle\AdminBundle\Controller;
|
||||
|
||||
use Sylius\Bundle\CoreBundle\Doctrine\ORM\AvatarRepository;
|
||||
use Sylius\Component\Core\Model\AvatarImage;
|
||||
use Sylius\Component\Core\Repository\AvatarRepositoryInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Templating\EngineInterface;
|
||||
use Symfony\Component\HttpFoundation\RedirectResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\RouterInterface;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
final class AvatarController
|
||||
{
|
||||
/** @var AvatarRepository */
|
||||
/** @var AvatarRepositoryInterface */
|
||||
private $avatarRepository;
|
||||
|
||||
/** @var EngineInterface */
|
||||
|
|
@ -34,8 +33,11 @@ final class AvatarController
|
|||
/** @var RouterInterface */
|
||||
private $router;
|
||||
|
||||
public function __construct(RepositoryInterface $avatarRepository, EngineInterface $templatingEngine, RouterInterface $router)
|
||||
{
|
||||
public function __construct(
|
||||
RepositoryInterface $avatarRepository,
|
||||
EngineInterface $templatingEngine,
|
||||
RouterInterface $router
|
||||
) {
|
||||
$this->avatarRepository = $avatarRepository;
|
||||
$this->templatingEngine = $templatingEngine;
|
||||
$this->router = $router;
|
||||
|
|
@ -45,8 +47,10 @@ final class AvatarController
|
|||
{
|
||||
/** @var AvatarImage $avatar */
|
||||
$avatar = $this->avatarRepository->findOneByOwner($id);
|
||||
Assert::notNull($avatar);
|
||||
$this->avatarRepository->remove($avatar);
|
||||
|
||||
if(null !== $avatar) {
|
||||
$this->avatarRepository->remove($avatar);
|
||||
}
|
||||
|
||||
$url = $this->router->generate('sylius_admin_admin_user_update', ['id' => $id]);
|
||||
|
||||
|
|
|
|||
|
|
@ -95,10 +95,6 @@ $(document).ready(() => {
|
|||
$(document).previewUploadedImage('#sylius_taxon_images');
|
||||
$(document).previewUploadedImage('#add-avatar');
|
||||
|
||||
$(document).on('click', '#delete-button', () => {
|
||||
$('.ui.small.bordered.image').remove('.ui.small.bordered.image');
|
||||
});
|
||||
|
||||
$('body').on('DOMNodeInserted', '[data-form-collection="item"]', (event) => {
|
||||
if ($(event.target).find('.accordion').length > 0) {
|
||||
$(event.target).find('.accordion').accordion();
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@
|
|||
<label>{{ 'sylius.ui.avatar'|trans }}</label>
|
||||
{{ form_row(form.avatar, {'label': false}) }}
|
||||
</div>
|
||||
<a href="{{ path('sylius_admin_admin_user_remove_avatar', {'id': app.request.attributes.get('id')}) }}" id="delete-button" class="ui icon red labeled button"><i class="icon trash"></i> {{ 'sylius.ui.delete'|trans }}</a>
|
||||
</div>
|
||||
<div class="ui segment">
|
||||
<h4 class="ui dividing header">{{ 'sylius.ui.preferences'|trans }}</h4>
|
||||
|
|
|
|||
|
|
@ -15,8 +15,9 @@ namespace Sylius\Bundle\CoreBundle\Doctrine\ORM;
|
|||
|
||||
use Sylius\Bundle\ResourceBundle\Doctrine\ORM\EntityRepository;
|
||||
use Sylius\Component\Core\Model\AvatarImage;
|
||||
use Sylius\Component\Core\Repository\AvatarRepositoryInterface;
|
||||
|
||||
final class AvatarRepository extends EntityRepository
|
||||
final class AvatarRepository extends EntityRepository implements AvatarRepositoryInterface
|
||||
{
|
||||
public function findOneByOwner(string $id): ?AvatarImage
|
||||
{
|
||||
|
|
|
|||
|
|
@ -98,7 +98,6 @@
|
|||
</div>
|
||||
<div style="margin-top: 10px" >
|
||||
<label for="{{ form.file.vars.id }}" class="ui icon labeled button"><i class="cloud upload icon"></i> {{ 'sylius.ui.choose_file'|trans }}</label>
|
||||
<label id="delete-button" class="ui icon red labeled button"><i class="icon trash"></i> {{ 'sylius.ui.delete'|trans }}</label>
|
||||
</div>
|
||||
<div class="ui element">
|
||||
{{- form_errors(form.file) -}}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Sylius package.
|
||||
*
|
||||
* (c) Paweł Jędrzejewski
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Sylius\Component\Core\Repository;
|
||||
|
||||
use Sylius\Component\Core\Model\AvatarImage;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
|
||||
interface AvatarRepositoryInterface extends RepositoryInterface
|
||||
{
|
||||
public function findOneByOwner(string $id): ?AvatarImage;
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue