-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e526b2d
commit 767ea8b
Showing
12 changed files
with
375 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\text_editor\controllers; | ||
|
||
use humhub\components\Controller; | ||
use humhub\modules\file\libs\FileHelper; | ||
use humhub\modules\text_editor\models\CreateFile; | ||
use humhub\modules\text_editor\Module; | ||
use Yii; | ||
use yii\helpers\Url; | ||
|
||
class CreateController extends Controller | ||
{ | ||
|
||
public function actionIndex() | ||
{ | ||
/* @var Module $module */ | ||
$module = Yii::$app->getModule('text-editor'); | ||
|
||
return $this->renderAjax('index', [ | ||
'types' => $module->getTypesData(), | ||
]); | ||
} | ||
|
||
public function actionFile() | ||
{ | ||
$model = new CreateFile(['fileType' => Yii::$app->request->get('type')]); | ||
|
||
if ($model->load(Yii::$app->request->post())) { | ||
if ($file = $model->save()) { | ||
return $this->asJson([ | ||
'success' => true, | ||
'file' => FileHelper::getFileInfos($file), | ||
'editFormUrl' => $model->openEditForm ? Url::to(['/text-editor/edit', 'guid' => $file->guid]) : false, | ||
]); | ||
} else { | ||
return $this->asJson([ | ||
'success' => false, | ||
'output' => $this->renderAjax('file', ['model' => $model]) | ||
]); | ||
} | ||
} | ||
|
||
return $this->renderAjax('file', ['model' => $model]); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\text_editor\filehandler; | ||
|
||
use humhub\modules\file\handler\BaseFileHandler; | ||
use Yii; | ||
use yii\helpers\Url; | ||
|
||
/** | ||
* CreateFileHandler provides the creating of a text file | ||
* | ||
* @author Luke | ||
*/ | ||
class CreateFileHandler extends BaseFileHandler | ||
{ | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function getLinkAttributes() | ||
{ | ||
return [ | ||
'label' => Yii::t('TextEditorModule.base', 'Create file <small>(Text, Log, XML)</small>'), | ||
'data-action-url' => Url::to(['/text-editor/create']), | ||
'data-action-click' => 'ui.modal.load', | ||
'data-modal-id' => 'texteditor-modal', | ||
'data-modal-close' => '' | ||
]; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<?php | ||
/** | ||
* @link https://www.humhub.org/ | ||
* @copyright Copyright (c) 2021 HumHub GmbH & Co. KG | ||
* @license https://www.humhub.com/licences | ||
*/ | ||
|
||
namespace humhub\modules\text_editor\models; | ||
|
||
use humhub\modules\text_editor\Module; | ||
use humhub\modules\file\models\File; | ||
use Yii; | ||
use yii\base\Exception; | ||
use yii\base\Model; | ||
|
||
/** | ||
* CreateFile is a form for create a new text file | ||
* | ||
* @author Luke | ||
*/ | ||
class CreateFile extends Model | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $fileType; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $fileName; | ||
|
||
/** | ||
* @var bool | ||
*/ | ||
public $openEditForm = true; | ||
|
||
public function init() | ||
{ | ||
/* @var Module $module */ | ||
$module = Yii::$app->getModule('text-editor'); | ||
|
||
if (!$module->isSupportedType($this->fileType)) { | ||
throw new Exception('Invalid file type!'); | ||
} | ||
|
||
parent::init(); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
['fileName', 'required'], | ||
['openEditForm', 'boolean'], | ||
]; | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
public function attributeLabels() | ||
{ | ||
return [ | ||
'openEditForm' => Yii::t('TextEditorModule.base', 'Edit the new file in the next step') | ||
]; | ||
} | ||
|
||
/** | ||
* @return false|File | ||
*/ | ||
public function save() | ||
{ | ||
/* @var $module Module */ | ||
$module = Yii::$app->getModule('text-editor'); | ||
|
||
if (!$this->validate()) { | ||
return false; | ||
} | ||
|
||
$file = new File(); | ||
$file->file_name = $this->fileName . '.' . $this->fileType; | ||
$file->size = 0; | ||
$file->mime_type = $module->getTypeInfo($this->fileType, 'mimeType'); | ||
if (!$file->save()) { | ||
return false; | ||
} | ||
|
||
$file->store->setContent(''); | ||
|
||
return $file; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
ul.text-editor-types { | ||
list-style: none; | ||
margin: 0; | ||
padding: 0; | ||
} | ||
ul.text-editor-types li { | ||
float: left; | ||
cursor: pointer; | ||
margin: 15px 25px; | ||
width: 135px; | ||
} | ||
|
||
a.text-editor-type { | ||
display: block; | ||
border: 1px solid #EEE; | ||
border-radius: 5px; | ||
padding: 12px; | ||
font-size: 14px; | ||
font-weight: bold; | ||
text-align: center; | ||
text-decoration: none; | ||
} | ||
a.text-editor-type .fa { | ||
display: block; | ||
font-size: 100px; | ||
margin-bottom: 10px; | ||
} | ||
|
||
a.text-editor-type.txt .fa { | ||
color: #333; | ||
} | ||
a.text-editor-type.txt:hover { | ||
background-color: #ddd; | ||
} | ||
a.text-editor-type.log .fa { | ||
color: #582F0E; | ||
} | ||
a.text-editor-type.log:hover { | ||
background-color: #ede0d4; | ||
} | ||
a.text-editor-type.xml .fa { | ||
color: #003049; | ||
} | ||
a.text-editor-type.xml:hover { | ||
background-color: #caf0f8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.