Skip to content

Commit

Permalink
Merge pull request #6 from ro4/master
Browse files Browse the repository at this point in the history
tag update
  • Loading branch information
mylxsw committed May 30, 2018
2 parents 63fb02a + f529e1e commit bd25137
Show file tree
Hide file tree
Showing 13 changed files with 889 additions and 3 deletions.
55 changes: 55 additions & 0 deletions app/Http/Controllers/TagController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Http\Controllers;


use App\Repositories\Document;
use App\Repositories\Tag;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Gate;

class TagController extends Controller
{

/**
* store the tags
*
* @param Request $request
*
* @return array|string
*/
public function store(Request $request)
{
$page_id = $request->input('p');
if (Gate::denies('project-edit', $page_id)) {
return [];
}
$tags = $request->input('tags');
$this->validateParameters(
[
'page_id' => $page_id,
'tags' => $tags,
],
[
'page_id' => "required|integer",
'tags' => 'nullable|max:500',
],
[
'tags.required' => '标签不能为空',
'tags.between' => '标签最大不能超过500字符',
]
);
/** @var Document $page */
$page = Document::findOrFail($page_id);
$names = explode(',', $tags);
$tags = [];
foreach ($names as $name) {
$tags[] = Tag::firstOrCreate(['name' => $name])->toArray();
}
$page->tags()->detach();
$page->tags()->attach(array_pluck($tags, 'id'));

return $tags;
}

}
10 changes: 10 additions & 0 deletions app/Repositories/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -147,4 +147,14 @@ public function attachments()
{
return $this->hasMany(Attachment::class, 'page_id', 'id');
}

/**
* 页面的标签
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function tags()
{
return $this->belongsToMany(Tag::class, 'wz_page_tag', 'page_id', 'tag_id');
}
}
19 changes: 19 additions & 0 deletions app/Repositories/PageTag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace App\Repositories;

/**
* Class Tag
*
* @property integer $id
* @property integer $page_id
* @property integer $tag_id
*
* @package App\Repositories
*/
class PageTag extends Repository
{
protected $table = 'wz_page_tag';
public $timestamps = false;
protected $fillable = ['page_id', 'tag_id'];
}
31 changes: 31 additions & 0 deletions app/Repositories/Tag.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Repositories;

use Carbon\Carbon;

/**
* Class Tag
*
* @property integer $id
* @property string $name
* @property Carbon $created_at
* @property Carbon $updated_at
*
* @package App\Repositories
*/
class Tag extends Repository
{
protected $table = 'wz_tags';
protected $fillable = ['name'];

/**
* 标签的页面
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
*/
public function pages()
{
return $this->belongsToMany(Document::class, 'wz_page_tag', 'tag_id', 'page_id');
}
}
32 changes: 32 additions & 0 deletions database/migrations/2018_05_10_105015_create_tags_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateTagsTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wz_tags', function (Blueprint $table) {
$table->increments('id');
$table->string('name', 255)->comment('用户ID')->unique();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('wz_tags');
}
}
34 changes: 34 additions & 0 deletions database/migrations/2018_05_10_105629_create_page_tag_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatePageTagTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('wz_page_tag', function (Blueprint $table) {
$table->increments('id');
$table->unsignedInteger('page_id')->comment('页面 ID');
$table->unsignedInteger('tag_id')->comment('标签 ID');
$table->index('page_id', 'idx_page_id');
$table->index('tag_id', 'idx_tag_id');
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('wz_page_tag');
}
}
10 changes: 10 additions & 0 deletions public/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -806,3 +806,13 @@ tr.warning {
display: inline-block;
vertical-align: middle;
}

.wz-tag {
padding: 1.5rem;
margin-right: 0;
margin-bottom: 0;
margin-left: 0;
border-width: .2rem;
position: relative;
max-width: 960px;
}
102 changes: 102 additions & 0 deletions public/assets/css/tagmanager.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*
* DO NOT EDIT THIS FILE DIRECTLY
* Compiled from bootstrap-tagmanager.less based on Bootstrap 2.3.1 variables
* https://github.com/twitter/bootstrap/blob/master/less/variables.less
*/
.tm-tag {
color: #555555;
background-color: #f5f5f5;
border: #bbbbbb 1px solid;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.075) inset;
display: inline-block;
border-radius: 3px;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
font-size: 13px;
margin: 0 5px 5px 0;
padding: 4px;
text-decoration: none;
transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;
-moz-transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;
-webkit-transition: border 0.2s linear 0s, box-shadow 0.2s linear 0s;
vertical-align: middle;
}
.tm-tag .tm-tag-remove {
color: #000000;
font-weight: bold;
margin-left: 4px;
opacity: 0.2;
}
.tm-tag .tm-tag-remove:hover {
color: #000000;
text-decoration: none;
opacity: 0.4;
}
.tm-tag.tm-tag-warning {
color: #945203;
background-color: #f2c889;
border-color: #f0a12f;
}
.tm-tag.tm-tag-error {
color: #84212e;
background-color: #e69ca6;
border-color: #d24a5d;
}
.tm-tag.tm-tag-success {
color: #638421;
background-color: #cde69c;
border-color: #a5d24a;
}
.tm-tag.tm-tag-info {
color: #4594b5;
background-color: #c5eefa;
border-color: #5dc8f7;
}
.tm-tag.tm-tag-inverse {
color: #cccccc;
background-color: #555555;
border-color: #333333;
box-shadow: 0 1px 1px rgba(0, 0, 0, 0.2) inset;
}
.tm-tag.tm-tag-inverse .tm-tag-remove {
color: #ffffff;
}
.tm-tag.tm-tag-large {
font-size: 16.25px;
border-radius: 4px;
padding: 11px 7px;
}
.tm-tag.tm-tag-small {
font-size: 11.049999999999999px;
border-radius: 3px;
padding: 2px 4px;
}
.tm-tag.tm-tag-mini {
font-size: 9.75px;
border-radius: 2px;
padding: 0px 2px;
}
.tm-tag.tm-tag-plain {
color: #333333;
box-shadow: none;
background: none;
border: none;
}
.tm-tag.tm-tag-disabled {
color: #aaaaaa;
background-color: #e6e6e6;
border-color: #cccccc;
box-shadow: none;
}
.tm-tag.tm-tag-disabled .tm-tag-remove {
display: none;
}
input[type="text"].tm-input {
margin-bottom: 5px;
vertical-align: middle !important;
}
.control-group.tm-group {
margin-bottom: 5px;
}
.form-horizontal .control-group.tm-group {
margin-bottom: 15px;
}
Loading

0 comments on commit bd25137

Please sign in to comment.