public function test()
 {
     self::assertInstanceOf(ContainerInterface::class, Services::container());
     self::assertTrue(is_array(Services::container()->get(ServiceId::CONFIG)));
     self::assertInstanceOf(RendererInterface::class, Services::renderer());
     self::assertInstanceOf(ResourceManager::class, Services::resourceManager());
 }
 /**
  * Demo1 extended by HtmlBuilder usage.
  *
  * @return string
  */
 public function demo2()
 {
     $html = Services::htmlBuilder();
     $data = $this->getUsersData();
     $view = new Container([$html->h1('Users List'), $html->hr(), new CollectionView($data, [new PersonView()]), $html->hr(), $html->div('Footer')]);
     return $this->page($view, 'HtmlBuilder');
 }
 /**
  * Returns renderer instance used to render template.
  *
  * @return RendererInterface
  */
 public function getRenderer()
 {
     if ($this->renderer === null) {
         $this->renderer = Services::renderer();
     }
     return $this->renderer;
 }
Exemple #4
0
 /**
  * DetailsRow constructor.
  *
  * @param DataViewComponentInterface $view details row content, will be initialized by data row
  * @param ResourceManager|null $resourceManager
  */
 public function __construct(DataViewComponentInterface $view, ResourceManager $resourceManager = null)
 {
     parent::__construct();
     $this->getRowTag()->setAttribute('style', 'display:none;')->setAttribute('data-details-row', '1');
     $this->addChild($this->view = $view);
     $this->setDestinationParentId(Grid::COLLECTION_VIEW_ID);
     $this->setId(static::ID);
     $this->resourceManager = $resourceManager ?: Services::resourceManager();
     $this->jquery = $this->resourceManager->js('jquery');
 }
 /**
  * SimpleRenderer constructor.
  *
  * @param TemplateFinder|null $finder
  */
 public function __construct(TemplateFinder $finder = null)
 {
     $this->finder = $finder ?: Services::templateFinder();
 }
Exemple #6
0
 public function getHistory()
 {
     $coins_list = function () {
         $data = ['' => 'All'];
         foreach (Cache::remember('coin_list', Config::get('cache.ttl'), function () {
             return Wallet::select('short as coin')->get();
         }) as $wallet) {
             $data[$wallet->coin] = $wallet->coin;
         }
         return $data;
     };
     $provider = new EloquentDataProvider(WalletsTransaction::selectRaw('wallets_transactions.id as id, wallets_transactions.amount, wallets_transactions.created_at, wallets_transactions.updated_at, wallets_transactions.txid, wallets_transactions.confirmed, wallets.short as coin')->where('user_id', Auth::user()->id)->leftJoin('wallets', 'wallets.id', '=', 'wallets_transactions.wallet_id'));
     Services::resourceManager()->ignoreCss(['bootstrap']);
     Services::resourceManager()->ignoreJs(['bootstrap']);
     $grid = new Grid($provider, [(new Column('wallets_transactions.id', 'ID'))->setValueFormatter(function ($value, WalletsTransaction $row = null) {
         if (!empty($row->id)) {
             return $row->id;
         } else {
             return $value;
         }
     }), new Column('txid', 'TxID'), (new Column('amount'))->setValueFormatter(function ($value, WalletsTransaction $row = null) {
         if (!empty($row)) {
             if ($value > 0) {
                 return HTML::tag('span', '+' . $value, ['class' => 'label label-success']);
             } else {
                 return HTML::tag('span', $value, ['class' => 'label label-danger']);
             }
         } else {
             return $value;
         }
     }), new Column('coin', 'Coin'), (new Column('confirmed'))->setValueFormatter(function ($value, WalletsTransaction $row = null) {
         if (!empty($row)) {
             if ($value) {
                 return HTML::tag('span', 'Confirmed', ['class' => 'label label-success']);
             } else {
                 return HTML::tag('span', 'Pending', ['class' => 'label label-info']);
             }
         }
     }), (new Column('wallets_transactions.created_at', 'Created At'))->setValueFormatter(function ($value, WalletsTransaction $row = null) {
         if (!empty($row->created_at)) {
             return $row->created_at;
         } else {
             return $value;
         }
     }), new Column('updated_at'), new AjaxDetailsRow(function (WalletsTransaction $row) {
         return url('/user/wallets/details', ['id' => $row->id]);
     }), new FilterControl('txid', FilterOperation::OPERATOR_STR_CONTAINS, new InputOption('txid', ['txid' => Input::get('txid')])), (new FilterControl('wallets.short', FilterOperation::OPERATOR_EQ, new InputOption('coin', ['coin' => Input::get('coin')])))->setView(new TemplateView('select', ['options' => $coins_list(), 'label' => 'Coin', 'inputAttributes' => ['style' => 'width: 50px;']])), (new FilterControl('confirmed', FilterOperation::OPERATOR_EQ, new InputOption('confirmed', ['confirmed' => Input::get('confirmed')])))->setView(new TemplateView('select', ['options' => ['' => 'All', 0 => 'Pending', 1 => 'Confirmed']])), new PageSizeSelectControl(new InputOption('ps', ['ps' => Input::get('ps')], 10), [10, 50, 100, 500, 1000]), new CsvExport(new InputOption('csv', ['csv' => Input::get('csv')])), new ResetButton(), new PageTotalsRow(['amount' => PageTotalsRow::OPERATION_SUM]), new PaginationControl(new InputOption('page', ['page' => Input::get('page')], 1), 10, $provider), new ColumnSortingControl('wallets_transactions.id', new InputOption('sort', ['sort' => Input::get('sort')], 'wallets_transactions.id-dir-desc')), new ColumnSortingControl('amount', new InputOption('sort', ['sort' => Input::get('sort')])), new ColumnSortingControl('wallets_transactions.created_at', new InputOption('sort', ['sort' => Input::get('sort')]))]);
     $customization = new BootstrapStyling();
     $customization->apply($grid);
     $grid = $grid->render();
     return view('user.wallets.history', compact('grid'));
 }
 /**
  * Constructor.
  *
  * @param ResourceManager $resourceManager
  */
 public function __construct(ResourceManager $resourceManager = null)
 {
     $this->resourceManager = $resourceManager ?: Services::resourceManager();
 }
Exemple #8
0
 public function demo14()
 {
     $this->prepareTiming();
     if (isset($_GET['details'])) {
         // mark resources as already included
         $manager = Services::resourceManager();
         $manager->js('jquery');
         $manager->js('bootstrap');
         $manager->css('bootstrap');
         return $this->demo14Details();
     }
     $grid = new Grid($provider = $this->getDataProvider(), [new Column('id'), new Column('name'), (new Column('age'))->setValueCalculator(function ($row) {
         return DateTime::createFromFormat('Y-m-d', $row->birthday)->diff(new DateTime('now'))->y;
     })->setValueFormatter(function ($val) {
         return "{$val} years";
     }), new AjaxDetailsRow(function ($row) {
         return "/index.php/demo14?details=1&id=" . $row->id;
     }), new PageTotalsRow(['id' => PageTotalsRow::OPERATION_IGNORE, 'age' => PageTotalsRow::OPERATION_AVG])]);
     $grid->attachTo($this->layout());
     $styling = new BootstrapStyling();
     $styling->apply($this->layout());
     $this->defaultCss->detach();
     return $this->page(null, 'AjaxDetailsRow (Click table rows to check)');
 }
Exemple #9
0
 public function getHistory()
 {
     $coins_list = function () {
         $data = ['' => 'All'];
         foreach (Cache::remember('coin_list', Config::get('cache.ttl'), function () {
             return Wallet::select('short as coin')->get();
         }) as $wallet) {
             $data[$wallet->coin] = $wallet->coin;
         }
         return $data;
     };
     $provider = new EloquentDataProvider(OrdersTransaction::selectRaw('0 as total, orders_transactions.fee as fee, orders_transactions.id as id, orders_transactions.order_id as order_id, orders_transactions.amount, orders_transactions.price, orders_transactions.created_at, orders_transactions.updated_at, orders_transactions.type, w1.short as coin1, w2.short as coin2')->where('user_id', Auth::user()->id)->leftJoin('wallets as w1', 'w1.id', '=', 'orders_transactions.wallet_id')->leftJoin('wallets as w2', 'w2.id', '=', 'orders_transactions.want_wallet_id'));
     Services::resourceManager()->ignoreCss(['bootstrap']);
     Services::resourceManager()->ignoreJs(['bootstrap']);
     $grid = new Grid($provider, [(new Column('orders_transactions.id', 'ID'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row->id)) {
             return $row->id;
         } else {
             return $value;
         }
     }), (new Column('orders_transactions.order_id', 'Order ID'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row->order_id)) {
             return $row->order_id;
         } else {
             return $value;
         }
     }), (new Column('coin1'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             return $row->coin2 . '/' . $row->coin1;
         } else {
             return $value;
         }
     }), (new Column('type'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             if ($value == 'buy') {
                 return HTML::tag('span', $value, ['class' => 'label label-success']);
             } else {
                 return HTML::tag('span', $value, ['class' => 'label label-danger']);
             }
         } else {
             return $value;
         }
     }), (new Column('amount'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             return HTML::tag('span', sprintf('%.8f %s', $row->amount, $row->coin2));
         } else {
             return $value;
         }
     }), (new Column('price'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             return HTML::tag('span', sprintf('%.8f %s', $row->price, $row->coin1));
         } else {
             return $value;
         }
     }), (new Column('fee'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             if ($row->type == 'sell') {
                 return HTML::tag('span', sprintf('%.8f %s (%.2f%%)', Order::calcFee($row->amount, $row->fee), $row->coin1, $row->fee));
             } else {
                 return HTML::tag('span', sprintf('%.8f %s (%.2f%%)', Order::calcFee($row->amount * $row->price, $row->fee), $row->coin2, $row->fee));
             }
         } else {
             return $value;
         }
     }), (new Column('total'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row)) {
             if ($row->type == 'buy') {
                 return HTML::tag('span', sprintf('%.8f %s', $row->amount - Order::calcFee($row->amount, $row->fee), $row->coin2));
             } else {
                 return HTML::tag('span', sprintf('%.8f %s', $row->amount * $row->price - Order::calcFee($row->amount * $row->price, $row->fee), $row->coin1));
             }
         } else {
             return $value;
         }
     }), (new Column('orders_transactions.created_at', 'Created At'))->setValueFormatter(function ($value, OrdersTransaction $row = null) {
         if (!empty($row->created_at)) {
             return $row->created_at;
         } else {
             return $value;
         }
     }), new Column('updated_at'), (new FilterControl('wallets.short', FilterOperation::OPERATOR_EQ, new InputOption('coin', ['coin' => Input::get('coin')])))->setView(new TemplateView('select', ['options' => $coins_list(), 'label' => 'Coin', 'inputAttributes' => ['style' => 'width: 50px;']])), new PageSizeSelectControl(new InputOption('ps', ['ps' => Input::get('ps')], 10), [10, 50, 100, 500, 1000]), new CsvExport(new InputOption('csv', ['csv' => Input::get('csv')])), new ResetButton(), new PageTotalsRow(['amount' => PageTotalsRow::OPERATION_SUM]), new PaginationControl(new InputOption('page', ['page' => Input::get('page')], 1), 10, $provider), new ColumnSortingControl('orders_transactions.id', new InputOption('sort', ['sort' => Input::get('sort')], 'orders_transactions.id-dir-desc')), new ColumnSortingControl('amount', new InputOption('sort', ['sort' => Input::get('sort')])), new ColumnSortingControl('orders_transactions.created_at', new InputOption('sort', ['sort' => Input::get('sort')]))]);
     $customization = new BootstrapStyling();
     $customization->apply($grid);
     $grid = $grid->render();
     return view('user.orders.history', compact('grid'));
 }
 /**
  * Constructor.
  *
  * @param ResourceManager|null $resourceManager
  */
 public function __construct(ResourceManager $resourceManager = null)
 {
     parent::__construct(Services::get(static::STYLING_CONFIG_SERVICE_ID), $resourceManager);
 }
 /**
  * Returns resource manager instance used by component.
  *
  * @return ResourceManager
  */
 protected function getResourceManager()
 {
     if ($this->resourceManager === null) {
         $this->resourceManager = Services::resourceManager();
     }
     return $this->resourceManager;
 }