Skip to content

Commit

Permalink
Merge pull request #32 from d3yii2/BugNeradaTukshuWidgetu
Browse files Browse the repository at this point in the history
IZlaboti bugi
  • Loading branch information
uldisn authored Dec 28, 2019
2 parents 8a5b681 + b787603 commit 2d60d4e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 33 deletions.
38 changes: 12 additions & 26 deletions widgets/D3FilesPreviewWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
use d3yii2\d3files\models\D3files as ModelD3Files;
use d3yii2\pdfobject\widgets\PDFObject;
use eaBlankonThema\assetbundles\AjaxAsset;
use eaBlankonThema\widget\ThButton;
use eaBlankonThema\widget\ThModal;
use Exception;
use yii\base\InvalidConfigException;
use yii\db\ActiveRecord;
use yii\helpers\Html;
use yii\helpers\Json;
Expand Down Expand Up @@ -149,10 +149,8 @@ public function init(): void
Yii::$app->view->params['ThModalRendered'] = true;

$pageFooterHtml .= $this->dialogWidgetClass::widget($modalOptions);
} else if(self::VIEW_TYPE_INLINE === $this->viewType) {

// Render the PdfObject content iframe in the footer if the files have PDF extension
if ($hasPdf) {
} else // Render the PdfObject content iframe in the footer if the files have PDF extension
if((self::VIEW_TYPE_INLINE === $this->viewType) && $hasPdf) {

$this->pdfObjectOptions = array_merge(
[
Expand All @@ -163,7 +161,6 @@ public function init(): void
);
echo $this->getPdfContent();
}
}

if ($pageFooterHtml) {
Yii::$app->view->setPageFooter($pageFooterHtml);
Expand Down Expand Up @@ -203,12 +200,11 @@ public function initFilesList()

/**
* @return string
* @throws \yii\base\InvalidConfigException
* @throws InvalidConfigException
*/
public function getAssetsUrl(): string
{
$bundleWebPath = Yii::$app->getAssetManager()->getBundle(D3FilesPreviewAsset::class)->baseUrl;
return $bundleWebPath;
return Yii::$app->getAssetManager()->getBundle(D3FilesPreviewAsset::class)->baseUrl;
}

/**
Expand Down Expand Up @@ -254,20 +250,12 @@ public function getFilesDropdown(): string
*/
public function getViewParams(): ?array
{
$file = D3Files::getFirstFileHavingExt($this->fileList, $this->viewExtension);

if (!$file) {
return null;
}

if (self::VIEW_FILES_LIST !== $this->viewType && ! D3Files::hasViewExtension([$file], $this->viewByExtensions)) {
return null;
$previewAttrs = [];
if($file = D3Files::getFirstFileHavingExt($this->fileList, $this->viewExtension)) {
$previewAttrs = self::VIEW_TYPE_MODAL === $this->viewType
? self::getPreviewModalButtonAttributes($this->model, $file, $this->fileList)
: self::getPreviewInlineButtonAttributes($this->model, $file, $this->fileList);
}

$previewAttrs = self::VIEW_TYPE_MODAL === $this->viewType
? self::getPreviewModalButtonAttributes($this->model, $file, $this->fileList)
: self::getPreviewInlineButtonAttributes($this->model, $file, $this->fileList);

$params = [
'file' => $file,
'modelId' => $this->model_id,
Expand All @@ -294,7 +282,7 @@ public function getViewParams(): ?array
*/
public static function getPreviewButtonDataAttributes(ActiveRecord $model, array $file, array $files): array
{
$attrs = [
return [
'data-d3files-preview' => Json::encode(
[
'active' => $file['id'],
Expand All @@ -304,7 +292,6 @@ public static function getPreviewButtonDataAttributes(ActiveRecord $model, array
),
];

return $attrs;
}

/**
Expand All @@ -315,13 +302,12 @@ public static function getPreviewButtonDataAttributes(ActiveRecord $model, array
*/
public static function getPreviewInlineButtonAttributes(ActiveRecord $model, array $file, array $files = []): array
{
$attrs = [
return [
'class' => PDFObject::LOAD_BUTTON_CLASS,
'data-src' => $file['src'],
'content-target' => self::EMBED_CONTENT_CLASS,
];

return $attrs;
}

/**
Expand Down
10 changes: 3 additions & 7 deletions widgets/D3FilesWidget.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Yii;
use yii\base\Widget;
use yii\db\ActiveRecord;
use yii\helpers\Json;

/**
* Class`D3FilesWidget`
Expand Down Expand Up @@ -75,7 +76,6 @@ class D3FilesWidget extends Widget
public const BUTTON_PLACEMENT_RIGHT = 'right';

/**
* @throws \yii\db\Exception
* @throws Exception
*/
public function init(): void
Expand Down Expand Up @@ -131,10 +131,6 @@ public function run()
try {
$viewParams = $this->getViewParams();

if (!$viewParams) {
return '';
}

return $this->render($this->view, $viewParams);
} catch (Exception $exception) {
Yii::error('D3FilesWidget:run Exception: ' . $exception->getMessage());
Expand Down Expand Up @@ -190,9 +186,9 @@ public function getFileList(): array
}


public function registerJsTranslations()
public function registerJsTranslations(): void
{
$i18n = \yii\helpers\Json::encode([
$i18n = Json::encode([
'aria_label' => Yii::t('d3files', 'Close'),
'confirm' => Yii::t('d3files', 'Are you sure you want to delete this item?'),
'no_results' => Yii::t('d3files', 'No results found.'),
Expand Down

0 comments on commit 2d60d4e

Please sign in to comment.