Skip to content

Commit

Permalink
attachment and tag
Browse files Browse the repository at this point in the history
  • Loading branch information
刘俊涛 committed Dec 10, 2016
1 parent 5025f95 commit 0d3079a
Show file tree
Hide file tree
Showing 31 changed files with 495 additions and 198 deletions.
22 changes: 5 additions & 17 deletions backend/assets/AttachmentIndexAsset.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,12 @@
<?php
/**
*
* HassCMS (http:https://www.hassium.org/)
*
* @link http:https://github.com/hasscms for the canonical source repository
* @copyright Copyright (c) 2016-2099 Hassium Software LLC.
* @license http:https://opensource.org/licenses/gpl-license.php GNU Public License
*/
namespace hass\attachment\assets;

namespace backend\assets;

use yii\web\AssetBundle;

/**
*
* @package hass\package_name
* @author zhepama <[email protected]>
* @since 0.1.0
*/
class AttachmentIndexAsset extends AssetBundle
{
public $sourcePath = '@hass/attachment/misc';
public $sourcePath = '@backend/static';
public $css = [
'attachment-index.css',
'attachment-info.css'
Expand All @@ -27,7 +15,7 @@ class AttachmentIndexAsset extends AssetBundle
'attachment-index.js',
];
public $depends = [
'hass\backend\assets\AdminAsset'
'backend\assets\AppAsset'
];
}

Expand Down
23 changes: 5 additions & 18 deletions backend/assets/AttachmentUpdateAsset.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
<?php
/**
*
* HassCMS (http:https://www.hassium.org/)
*
* @link http:https://github.com/hasscms for the canonical source repository
* @copyright Copyright (c) 2016-2099 Hassium Software LLC.
* @license http:https://opensource.org/licenses/gpl-license.php GNU Public License
*/
namespace hass\attachment\assets;
namespace backend\assets;

use yii\web\AssetBundle;

/**
*
* @package hass\package_name
* @author zhepama <[email protected]>
* @since 0.1.0
*/
class AttachmentUpdateAsset extends AssetBundle
{
public $sourcePath = '@hass/attachment/misc';
public $sourcePath = '@backend/static';
public $css = [
'attachment-update.css',
'attachment-info.css'
Expand All @@ -27,8 +14,8 @@ class AttachmentUpdateAsset extends AssetBundle
'attachment-update.js',
];
public $depends = [
'hass\backend\assets\AdminAsset',
'hass\base\misc\jcrop\JcropAsset'
'backend\assets\AppAsset',
'common\widgets\upload\JcropAsset'
];
}

Expand Down
23 changes: 5 additions & 18 deletions backend/assets/AttachmentUploadAsset.php
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
<?php
/**
*
* HassCMS (http:https://www.hassium.org/)
*
* @link http:https://github.com/hasscms for the canonical source repository
* @copyright Copyright (c) 2016-2099 Hassium Software LLC.
* @license http:https://opensource.org/licenses/gpl-license.php GNU Public License
*/
namespace hass\attachment\assets;
namespace backend\assets;

use yii\web\AssetBundle;

/**
*
* @package hass\package_name
* @author zhepama <[email protected]>
* @since 0.1.0
*/
class AttachmentUploadAsset extends AssetBundle
{
public $sourcePath = '@hass/attachment/misc';
public $sourcePath = '@backend/static';
public $css = [
'attachment-upload.css',
];
Expand All @@ -28,8 +15,8 @@ class AttachmentUploadAsset extends AssetBundle
public $depends = [
'yii\web\JqueryAsset',
'yii\bootstrap\BootstrapAsset',
'hass\base\misc\blueimpFileupload\BlueimpFileuploadAsset',
'hass\backend\assets\AdminAsset'
'common\widgets\upload\blueimpFileupload\BlueimpFileuploadAsset',
'backend\assets\AppAsset'
];
}

Expand Down
99 changes: 98 additions & 1 deletion backend/controllers/AttachmentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,105 @@

namespace backend\controllers;

use Yii;
use common\models\Attachment;
use common\components\WebController as Controller;
use yii\imagine\Image;
use yii\web\NotFoundHttpException;
use yii\data\ActiveDataProvider;

class AttachmentController

class AttachmentController extends Controller
{
/**
* Lists all Gather models.
* @return mixed
*/
public function actionIndex()
{
$dataProvider = new ActiveDataProvider([
'query' => Attachment::find(),
]);

return $this->render('index', [
'dataProvider' => $dataProvider,
]);
}
public function actionView($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post())) {
if (!$model->save()) {
$error = current($model->getFirstErrors());
return $this->renderJson(0, $error);
}
}

$content = $this->renderPartial('view', [
'model' => $model
]);

return $this->renderJson(1, $content);
}

public function actionUpdate($id)
{
$model = $this->findModel($id);

if ($model->load(Yii::$app->request->post()) && $model->save()) {
return $this->refresh();
} else {
return $this->render('update', [
'model' => $model,
]);
}
}

public function actionUploader()
{
return $this->render("uploader");
}

public function actionCrop($id)
{
$model = $this->findModel($id);
$type = \Yii::$app->getRequest()->post("type");
$x = \Yii::$app->getRequest()->post("x");
$y = \Yii::$app->getRequest()->post("y");
$w = \Yii::$app->getRequest()->post("w");
$h = \Yii::$app->getRequest()->post("h");
$original = $model->getAbsolutePath();
Image::crop($original, $w, $h, [
$x,
$y
])->save($original);
$model->deleteThumbs();
return $this->renderJson(1, "裁剪成功");
}

public function actionDelete($id)
{
$this->findModel($id)->delete();
if (Yii::$app->request->isAjax) {
return $this->renderJson(1, '删除成功');
}
return $this->redirect(['index']);
}
/**
* Finds the Attachment model based on its primary key value.
* If the model is not found, a 404 HTTP exception will be thrown.
*
* @param integer $id
* @return Attachment the loaded model
* @throws NotFoundHttpException if the model cannot be found
*/
protected function findModel($id)
{
if (($model = Attachment::findOne($id)) !== null) {
return $model;
} else {
throw new NotFoundHttpException('The requested page does not exist.');
}
}
}
6 changes: 3 additions & 3 deletions backend/models/MediaItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
* @copyright Copyright (c) 2016-2099 Hassium Software LLC.
* @license http:https://opensource.org/licenses/gpl-license.php GNU Public License
*/
namespace hass\attachment\helpers;
use hass\attachment\models\Attachment;
namespace backend\models;
use common\models\Attachment;

/**
*
Expand Down Expand Up @@ -87,7 +87,7 @@ public function __construct($path, $size, $lastModified, $type, $publicUrl)
public static function createFromAttachment($attachment)
{
$file = $attachment->getFile();
$item = new static($attachment->getAbsolutePath(),$file->getSize(),$file->getTimestamp(),$file->getType(),$attachment->getUrl());
$item = new static($attachment->getAbsolutePath(),$file->getSize(),$file->getTimestamp(),$file->getType(),$attachment->url);
return $item;
}

Expand Down
30 changes: 15 additions & 15 deletions backend/static/attachment-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ $(document).ready(function() {
$("#attachment-info").html('<div class="loading"><i class="fa fa-spinner fa-pulse fa-5x"></i></div>');
}

$('#attachment-list').on("click", "a", function(e) {
$(document).on("click", "#attachment-list a", function(e) {
e.preventDefault();
e.stopImmediatePropagation();

Expand All @@ -21,10 +21,10 @@ $(document).ready(function() {
setAjaxLoader();
},
success: function(msg) {
if (msg.status == false) {
alert(msg.content);
if (msg.status == 0) {
alert(msg.message);
} else {
$("#attachment-info").html(msg.content);
$("#attachment-info").html(msg.message);
}

}
Expand All @@ -40,21 +40,21 @@ $(document).ready(function() {
var url = $(this).attr("href");
var confirmMessage = $(this).data("confirm-msg");
var id = $(this).data("item-id");
if (!confirm(confirmMessage)) {
return false;
}
$.ajax({
type: "POST",
url: url,
beforeSend: function() {
if (!confirm(confirmMessage)) {
return false;
}
setAjaxLoader();
},
success: function(msg) {
if (msg.status == true) {
success: function(res) {
if (res.status == 1) {
$("#attachment-info").html("");
$('#attachment-list .item[data-item-id="' + id + '"]').fadeOut();
}
notify.msg(msg.status, msg.content);
$.modal.msg(res.message, res.status);
}
});

Expand All @@ -74,12 +74,12 @@ $(document).ready(function() {
beforeSend: function() {
setAjaxLoader();
},
success: function(msg) {
if (msg.status == false) {
alert(msg.content);
success: function(res) {
if (res.status == false) {
$.modal.error(res.message);
} else {
$("#attachment-info").html(msg.content);
notify.msg(msg.status, "更新成功");
$("#attachment-info").html(res.message);
$.modal.success("更新成功");
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion backend/static/attachment-update.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ $(document).ready(function() {

jcrop_api.newSelection();

var bound =getRandom();
var bound = getRandom();
jcrop_api.setSelect(bound);

$('#crop-x').val(bound[0]);
Expand Down
2 changes: 1 addition & 1 deletion backend/static/attachment-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ $(document).ready(function() {
item.append($('<a class="edit-attachment" target="_blank" href="'+file.updateUrl+'">编辑</a>'));

var title = $('<div>', {"class": "filename new"})
.html('<span class="title">'+file.name+'</span>');
.html('<span class="title">'+file.filename+'</span>');

item.append(title);

Expand Down
26 changes: 14 additions & 12 deletions backend/views/attachment/_info.php
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<?php
use hass\attachment\helpers\MediaItem;
use backend\models\MediaItem;

/**
* @var \common\models\Attachment $model
*/
$media = MediaItem::createFromAttachment($model);
?>
<?php if (is_file($media->path)):?>
<div id="misc-publishing-actions">
<div class="misc-pub-section curtime misc-pub-curtime">
<span id="timestamp">上传于:<?= $model->getCreatedDateTime()?></span>
<span id="timestamp">上传于:<?= Yii::$app->formatter->asDatetime($model->created_at) ?></span>
</div>
<!-- .misc-pub-section -->

<div class="misc-pub-section misc-pub-attachment">
<label for="attachment_url">文件URL:</label> <input type="text"
class="form-control" readonly="readonly" name="attachment_url"
value="<?php echo $model->getUrl();?>">
<label for="attachment_url">文件URL:</label>
<input type="text" class="form-control" readonly="readonly" id="attachment_url" value="<?= $model->url;?>" />
</div>

<div class="misc-pub-section misc-pub-filetype">
Expand All @@ -23,14 +26,13 @@ class="form-control" readonly="readonly" name="attachment_url"
文件大小: <strong><?= $media->sizeToString() ?></strong>
</div>

<div class="misc-pub-section misc-pub-filename">
文件名: <strong><?php echo $model->name.".".$model->extension;?></strong>
<div class="misc-pub-section misc-pub-filename">
文件名: <strong><?= $model->name ?></strong>
</div>
<?php if ($media->isImage()) : ?>
<div class="misc-pub-section misc-pub-dimensions">
分辨率: <strong><span ><?= $media->getResolution() ?></span>
</strong>
<?php if ($media->isImage()) : ?>
<div class="misc-pub-section misc-pub-dimensions">
宽高: <strong><span ><?= $media->getResolution() ?></span></strong>
</div>
<?php endif; ?>
<?php endif; ?>
</div>
<?php endif;?>
2 changes: 1 addition & 1 deletion backend/views/attachment/_update_audio.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
/** @var \hass\attachment\helpers\MediaItem $media */
?>
<div class=" attachment_audio">
<?php echo Html::tag("audio","Your browser does not support the audio tag.",["src"=>$model->getUrl(), "controls"=>"controls"])?>
<?php echo Html::tag("audio","Your browser does not support the audio tag.",["src"=>$model->url, "controls"=>"controls"])?>
</div>
Loading

0 comments on commit 0d3079a

Please sign in to comment.