Ejemplo n.º 1
0
 public function create($modelName, $item = null, ModelConfig $config = null)
 {
     $page = new Page();
     $header = new PageHeader();
     $header->setText('Create ' . $modelName);
     if ($item != null && isset($item->id)) {
         $model = $this->aujaConfigurator->getModel($modelName);
         $displayField = $this->aujaConfigurator->getDisplayField($model, $config);
         $header->setText('Edit ' . (isset($item->{$displayField}) ? $item->{$displayField} : $modelName));
         $deleteButton = new Button();
         $deleteButton->setText(Lang::trans('Delete'));
         $deleteButton->setConfirmationMessage(Lang::trans('Are you sure?'));
         $deleteButton->setTarget(URL::route($this->aujaRouter->getDeleteName($modelName), $item->id));
         $deleteButton->setMethod('delete');
         $header->addButton($deleteButton);
     }
     $page->addPageComponent($header);
     $form = new Form();
     $action = $item == null || !isset($item->id) ? URL::route($this->aujaRouter->getStoreName($modelName)) : URL::route($this->aujaRouter->getUpdateName($modelName), $item->id);
     $form->setAction($action);
     $form->setMethod($item == null ? 'POST' : 'PUT');
     $model = $this->aujaConfigurator->getModel($modelName);
     $visibleFields = $this->aujaConfigurator->getVisibleFields($model, $config);
     foreach ($visibleFields as $columnName) {
         $column = $model->getColumn($columnName);
         $formItem = $this->formItemFactory->getFormItem($model, $column, $item);
         $form->addFormItem($formItem);
     }
     $submit = new SubmitFormItem();
     $submit->setText(Lang::trans('Submit'));
     $form->addFormItem($submit);
     $page->addPageComponent($form);
     return $page;
 }
 /**
  * Builds a menu for displaying associated items to a model entry (i.e. /club/21/team).
  *
  * The menu will include:
  *  - An Add LinkMenuItem;
  *  - A SpacerMenuItem with the name of the associated model;
  *  - A ResourceMenuItem to hold entries of the associated model.
  *
  * @param String      $modelName       The name of the model (i.e. Club).
  * @param int         $modelId         The id of the model entry.
  * @param String      $associationName The name of the associated model (i.e. Team).
  * @param ModelConfig $config          (optional) The `ModelConfig` to use.
  *
  * @return Menu the Menu, which can be configured further.
  */
 public function create($modelName, $modelId, $associationName, ModelConfig $config = null)
 {
     $menu = new Menu();
     $addMenuItem = new LinkMenuItem();
     $addMenuItem->setText(Lang::trans('Add') . ' ' . Lang::trans($associationName));
     $addMenuItem->setIcon(Icons::ion_plus);
     $addMenuItem->setTarget(Url::route($this->aujaRouter->getCreateAssociationName($modelName, $associationName), $modelId));
     $menu->addMenuItem($addMenuItem);
     $headerMenuItem = new SpacerMenuItem();
     $headerMenuItem->setText(Lang::trans(str_plural($associationName)));
     $menu->addMenuItem($headerMenuItem);
     $resourceMenuItem = new ResourceMenuItem();
     $resourceMenuItem->setTarget(Url::route($this->aujaRouter->getAssociationName($modelName, $associationName), $modelId));
     $menu->addMenuItem($resourceMenuItem);
     return $menu;
 }
 /**
  * Bootstrap the application services.
  *
  * @return void
  */
 public function boot()
 {
     $this->loadTranslationsFrom(__DIR__ . '/../../resources/lang', 'instance-validator');
     $this->publishes([__DIR__ . '/../../resources/lang' => resource_path('lang/vendor/instance-validator')]);
     Validator::extend('instance_of', function ($attribute, $value, $parameters, $validator) {
         if (count($parameters) != 1) {
             throw new Exception("The 'instance_of' validator requires a single type to be specified.");
         }
         return $value instanceof $parameters[0];
     });
     Validator::replacer('instance_of', function ($message, $attribute, $rule, $parameters) {
         $msg = Lang::trans('instance-validator::' . $message);
         $msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
         return $msg;
     });
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     Validator::extend('collection_of', function ($attribute, $value, $parameters, $validator) {
         if (count($parameters) != 1) {
             throw new Exception("The 'collection_of' validator requires a single type to be specified.");
         }
         $isCollection = $value instanceof Collection;
         $itemIsCorrectType = $value[0] instanceof $parameters[0] || strtolower($parameters[0]) === 'string' && is_string($value[0]);
         return $isCollection && $itemIsCorrectType;
     });
     Validator::replacer('collection_of', function ($message, $attribute, $rule, $parameters) {
         $msg = Lang::trans('instance-validator::' . $message);
         $msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
         return $msg;
     });
     // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     Validator::extend('paginator_of', function ($attribute, $value, $parameters, $validator) {
         if (count($parameters) != 1) {
             throw new Exception("The 'paginator_of' validator requires a single type to be specified.");
         }
         if (!$value instanceof LengthAwarePaginator) {
             throw new Exception("The 'paginator_of' validator requires a LengthAwarePaginator instance.");
         }
         $itemIsCorrectType = $value->items()[0] instanceof $parameters[0] || strtolower($parameters[0]) === 'string' && is_string($value->items()[0]);
         return $itemIsCorrectType;
     });
     Validator::replacer('paginator_of', function ($message, $attribute, $rule, $parameters) {
         $msg = Lang::trans('instance-validator::' . $message);
         $msg = str_replace([':attribute', ':type'], [$attribute, $parameters[0]], $msg);
         return $msg;
     });
 }
 /**
  * Builds a menu for a single model entry, where the model has multiple relationships with other models.
  *
  * The menu will include:
  *  - An Edit LinkMenuItem;
  *  - A SpacerMenuItem;
  *  - For each of the Relations, a LinkMenuItem for the associated model.
  *
  * @param String     $modelName the name of the model.
  * @param int        $modelId   the id of the model entry.
  * @param Relation[] $relations the Relations this model has with associated models.
  *
  * @return Menu the Menu, which can be configured further.
  */
 public function create($modelName, $modelId, array $relations, ModelConfig $config = null)
 {
     $menu = new Menu();
     $addMenuItem = new LinkMenuItem();
     $addMenuItem->setText(Lang::trans('Edit'));
     $addMenuItem->setTarget(URL::route($this->aujaRouter->getEditName($modelName), $modelId));
     $menu->addMenuItem($addMenuItem);
     $spacerMenuItem = new SpacerMenuItem();
     $spacerMenuItem->setText(Lang::trans('Properties'));
     $menu->addMenuItem($spacerMenuItem);
     foreach ($relations as $relation) {
         $otherModelName = $relation->getRight()->getName();
         $associationMenuItem = new LinkMenuItem();
         $associationMenuItem->setText(Lang::trans(str_plural($otherModelName)));
         $associationMenuItem->setTarget(URL::route($this->aujaRouter->getAssociationMenuName($modelName, $otherModelName), $modelId));
         $menu->addMenuItem($associationMenuItem);
     }
     return $menu;
 }
 /**
  * Builds a menu for a single model entry, where the model has exactly one relationship with another model.
  *
  * The menu will include:
  *  - An Edit LinkMenuItem to edit the model entry.
  *  - A SpacerMenuItem with the name of the associated model;
  *  - An Add LinkMenuItem to add an entry of the associated model;
  *  - A ResourceMenuItem to hold entries of the associated model.
  *
  * @param String      $modelName The name of the model.
  * @param int         $modelId   The id of the model entry.
  * @param Relation    $relation  The Relation this model has with the associated model.
  * @param ModelConfig $config    (optional) The `ModelConfig` to use.
  *
  * @return Menu The Menu, which can be configured further.
  */
 public function create($modelName, $modelId, Relation $relation, ModelConfig $config = null)
 {
     $otherModelName = $relation->getRight()->getName();
     $menu = new Menu();
     $editMenuItem = new LinkMenuItem();
     $editMenuItem->setText(Lang::trans('Edit'));
     $editMenuItem->setTarget(URL::route($this->aujaRouter->getEditName($modelName), $modelId));
     $menu->addMenuItem($editMenuItem);
     $headerMenuItem = new SpacerMenuItem();
     $headerMenuItem->setText(Lang::trans(str_plural($otherModelName)));
     $menu->addMenuItem($headerMenuItem);
     $addMenuItem = new LinkMenuItem();
     $addMenuItem->setText(sprintf('%s %s', Lang::trans('Add'), Lang::trans($otherModelName)));
     $addMenuItem->setIcon(Icons::ion_plus);
     $addMenuItem->setTarget(URL::route($this->aujaRouter->getCreateAssociationName($modelName, $otherModelName), $modelId));
     $menu->addMenuItem($addMenuItem);
     $resourceMenuItem = new ResourceMenuItem();
     $resourceMenuItem->setTarget(URL::route($this->aujaRouter->getAssociationName($modelName, $otherModelName), $modelId));
     $menu->addMenuItem($resourceMenuItem);
     return $menu;
 }
 public function create($title, $target)
 {
     $result = new Form();
     $result->setAction($target);
     $result->setMethod('POST');
     $header = new FormHeader();
     $header->setText($title);
     $result->addFormItem($header);
     $usernameTextFormItem = new TextFormItem();
     $usernameTextFormItem->setName('email');
     $usernameTextFormItem->setLabel(Lang::trans('Email address'));
     $result->addFormItem($usernameTextFormItem);
     $passwordFormItem = new PasswordFormItem();
     $passwordFormItem->setName('password');
     $passwordFormItem->setLabel(Lang::trans('Password'));
     $result->addFormItem($passwordFormItem);
     $submitFormItem = new SubmitFormItem();
     $submitFormItem->setText(Lang::trans('Login'));
     $result->addFormItem($submitFormItem);
     return $result;
 }
 /**
  * Builds a simple menu for given model, where typically this model should not have any relations to other models.
  *
  * The menu will include:
  *  - An Add LinkMenuItem;
  *  - A SpacerMenuItem with the model's name;
  *  - A ResourceMenuItem to hold entries of the model.
  *
  * @param String      $modelName The name of the model.
  * @param ModelConfig $config    (optional) The `ModelConfig` to use.
  *
  * @return Menu the Menu, which can be configured further.
  */
 public function create($modelName, ModelConfig $config = null)
 {
     $menu = new Menu();
     $addMenuItem = new LinkMenuItem();
     $addMenuItem->setText(Lang::trans('Add'));
     $addMenuItem->setIcon(Icons::ion_plus);
     $addMenuItem->setTarget(URL::route($this->aujaRouter->getCreateName($modelName)));
     $menu->addMenuItem($addMenuItem);
     $spacerMenuItem = new SpacerMenuItem();
     $spacerMenuItem->setText(Lang::trans($modelName));
     $menu->addMenuItem($spacerMenuItem);
     $resourceMenuItem = new ResourceMenuItem();
     $resourceMenuItem->setTarget(URL::route($this->aujaRouter->getIndexName($modelName)));
     $model = $this->aujaConfigurator->getModel($modelName);
     if ($this->aujaConfigurator->isSearchable($model, $config)) {
         $target = urldecode(URL::route($this->aujaRouter->getIndexName($modelName), ['q' => '%s']));
         /* urldecode because the '%' gets escaped. */
         $property = new Searchable($target);
         $resourceMenuItem->addProperty($property);
     }
     $menu->addMenuItem($resourceMenuItem);
     return $menu;
 }
Ejemplo n.º 8
0
 /**
  * Returns a `FormItem` based on the type of the `Column`.
  *
  * @param Model     $model  The `Model` which contains given `Column`.
  * @param Column    $column The `Column` to create a `FormItem` for.
  * @param \Eloquent $item   The instance to retrieve information from for filling the `FormItem`.
  *
  * @return FormItem The created `FormItem`.
  */
 private function createFromType(Model $model, Column $column, $item)
 {
     $result = null;
     switch ($column->getType()) {
         case Type::TEXT:
         case Type::TARRAY:
         case Type::SIMPLE_ARRAY:
         case Type::JSON_ARRAY:
         case Type::OBJECT:
         case Type::BLOB:
             $result = new TextAreaFormItem();
             break;
         case Type::INTEGER:
         case Type::SMALLINT:
         case Type::BIGINT:
             $result = new IntegerFormItem();
             break;
         case Type::DECIMAL:
         case Type::FLOAT:
             $result = new NumberFormItem();
             break;
         case Type::BOOLEAN:
             $result = new CheckboxFormItem();
             break;
         case Type::DATE:
             $result = new DateFormItem();
             break;
         case Type::DATETIME:
         case Type::DATETIMETZ:
             $result = new DateTimeFormItem();
             break;
         case Type::TIME:
             $result = new TimeFormItem();
             break;
         case Type::STRING:
         case Type::GUID:
         default:
             $result = new TextFormItem();
             break;
     }
     $columnName = $column->getName();
     $result->setName($columnName);
     $result->setLabel(Lang::trans($this->aujaConfigurator->getColumnDisplayName($model, $columnName)));
     if ($item != null && isset($item->{$columnName})) {
         $result->setValue($item->{$columnName});
     }
     return $result;
 }
Ejemplo n.º 9
0
 public function lang($key)
 {
     return Lang::trans("mediabrowser::mediabrowser.{$key}");
 }
Ejemplo n.º 10
0
 /**
  * A basic functional test example.
  *
  * @return void
  */
 public function testMainPage()
 {
     $response = $this->call('GET', '/');
     $this->assertEquals(200, $response->getStatusCode());
     $this->visit('/')->seeStatusCode(200)->see(Lang::trans('interface.intro'));
 }