Skip to content

Commit

Permalink
增加Table类型的文档
Browse files Browse the repository at this point in the history
  • Loading branch information
mylxsw committed Apr 19, 2019
1 parent 42fb6a5 commit 59a88bd
Show file tree
Hide file tree
Showing 26 changed files with 1,466 additions and 48 deletions.
2 changes: 1 addition & 1 deletion app/Http/Controllers/DashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function index(Request $request)
->select(\DB::raw('type, count(id) as document_count'))
->get()
->mapWithKeys(function ($item) {
$type = $item['type'] == Document::TYPE_DOC ? 'markdown' : 'swagger';
$type = documentType($item['type']);
return [
$type => $item['document_count']
];
Expand Down
16 changes: 11 additions & 5 deletions app/Http/Controllers/DocumentController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
class DocumentController extends Controller
{

protected $types = [
Document::TYPE_DOC => 'doc',
Document::TYPE_SWAGGER => 'swagger',
Document::TYPE_TABLE => 'table',
];

/**
* 创建一个新文档页面
*
Expand All @@ -39,7 +45,7 @@ public function newPage(Request $request, $id)
{
$this->validate(
$request,
['type' => 'in:swagger,doc', 'pid' => 'integer|min:0']
['type' => 'in:swagger,doc,table', 'pid' => 'integer|min:0']
);

/** @var Project $project */
Expand Down Expand Up @@ -74,7 +80,7 @@ public function editPage($id, $page_id)

$this->authorize('page-edit', $pageItem);

$type = ((int)$pageItem->type === Document::TYPE_DOC ? 'doc' : 'swagger');
$type = $this->types[$pageItem->type];
return view("doc.{$type}", [
'pageItem' => $pageItem,
'project' => $pageItem->project,
Expand Down Expand Up @@ -102,7 +108,7 @@ public function newPageHandle(Request $request, $id)
[
'project_id' => "required|integer|min:1|in:{$id}|project_exist",
'title' => 'required|between:1,255',
'type' => 'required|in:doc,swagger',
'type' => 'required|in:doc,swagger,table',
'pid' => 'integer|min:0',
'sort_level' => 'integer',
],
Expand All @@ -129,7 +135,7 @@ public function newPageHandle(Request $request, $id)
'project_id' => $projectID,
'user_id' => \Auth::user()->id,
'last_modified_uid' => \Auth::user()->id,
'type' => $type == 'doc' ? Document::TYPE_DOC : Document::TYPE_SWAGGER,
'type' => array_flip($this->types)[$type],
'status' => 1,
'sort_level' => $sortLevel,
]);
Expand Down Expand Up @@ -428,7 +434,7 @@ public function readMode($id, $page_id)
}

$page = Document::where('project_id', $id)->where('id', $page_id)->firstOrFail();
$type = $page->type == Document::TYPE_DOC ? 'markdown' : 'swagger';
$type = $this->types[$page->type];

return view('share-show', [
'project' => $project,
Expand Down
8 changes: 7 additions & 1 deletion app/Http/Controllers/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@

class ProjectController extends Controller
{
protected $types = [
Document::TYPE_DOC => 'markdown',
Document::TYPE_SWAGGER => 'swagger',
Document::TYPE_TABLE => 'table',
];

/**
* 用户个人首页(个人项目列表)
*
Expand Down Expand Up @@ -175,7 +181,7 @@ public function project(Request $request, $id)
->where('project_id', $id)
->where('id', $pageID)
->firstOrFail();
$type = $page->type == Document::TYPE_DOC ? 'markdown' : 'swagger';
$type = $this->types[$page->type];

$history = DocumentHistory::where('page_id', $page->id)
->where('id', '!=', $page->history_id)
Expand Down
45 changes: 23 additions & 22 deletions app/Repositories/Document.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,36 @@
/**
* Class Page
*
* @property integer $id
* @property integer $pid
* @property string $title
* @property string $description
* @property string $content
* @property integer $project_id
* @property integer $user_id
* @property integer $last_modified_uid
* @property integer $history_id
* @property integer $type
* @property integer $status
* @property integer $sort_level
* @property Carbon $created_at
* @property Carbon $updated_at
* @property integer $id
* @property integer $pid
* @property string $title
* @property string $description
* @property string $content
* @property integer $project_id
* @property integer $user_id
* @property integer $last_modified_uid
* @property integer $history_id
* @property integer $type
* @property integer $status
* @property integer $sort_level
* @property Carbon $created_at
* @property Carbon $updated_at
* @package App\Repositories
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Attachment[] $attachments
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Comment[] $comments
* @property-read \App\Repositories\User $lastModifiedUser
* @property-read \App\Repositories\Document $parentPage
* @property-read \App\Repositories\Project $project
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Document[] $subPages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Tag[] $tags
* @property-read \App\Repositories\User $user
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Comment[] $comments
* @property-read \App\Repositories\User $lastModifiedUser
* @property-read \App\Repositories\Document $parentPage
* @property-read \App\Repositories\Project $project
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Document[] $subPages
* @property-read \Illuminate\Database\Eloquent\Collection|\App\Repositories\Tag[] $tags
* @property-read \App\Repositories\User $user
* @method static bool|null forceDelete()
* @method static \Illuminate\Database\Query\Builder|\App\Repositories\Document onlyTrashed()
* @method static bool|null restore()
* @method static \Illuminate\Database\Query\Builder|\App\Repositories\Document withTrashed()
* @method static \Illuminate\Database\Query\Builder|\App\Repositories\Document withoutTrashed()
* @mixin \Eloquent
* @property \Carbon\Carbon|null $deleted_at
* @property \Carbon\Carbon|null $deleted_at
* @method static \Illuminate\Database\Eloquent\Builder|\App\Repositories\Document whereContent($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Repositories\Document whereCreatedAt($value)
* @method static \Illuminate\Database\Eloquent\Builder|\App\Repositories\Document whereDeletedAt($value)
Expand All @@ -66,6 +66,7 @@ class Document extends Repository

const TYPE_DOC = 1;
const TYPE_SWAGGER = 2;
const TYPE_TABLE = 3;

protected $table = 'wz_pages';
protected $fillable
Expand Down
21 changes: 19 additions & 2 deletions app/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,24 @@ function wzRoute($name, $parameters = [], $absolute = false)
return route($name, $parameters, $absolute);
}

/**
* 文档类型标识转换
*
* @param $type
*
* @return string
*/
function documentType($type): string
{
$types = [
\App\Repositories\Document::TYPE_DOC => 'markdown',
\App\Repositories\Document::TYPE_SWAGGER => 'swagger',
\App\Repositories\Document::TYPE_TABLE => 'table',
];

return $types[$type] ?? '';
}

/**
* 将页面集合转换为层级结构的菜单
*
Expand Down Expand Up @@ -56,8 +74,7 @@ function navigator(
'pid' => (int)$page->pid,
'url' => route('project:home', ['id' => $projectID, 'p' => $page->id]),
'selected' => $pageID === (int)$page->id,
'type' => $page->type == \App\Repositories\Document::TYPE_DOC ? 'markdown'
: 'swagger',
'type' => documentType($page->type),
'created_at' => $page->created_at,
'sort_level' => $page->sort_level ?? 1000,
];
Expand Down
20 changes: 19 additions & 1 deletion public/assets/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,17 @@ a:hover {

.wz-edit-control {
margin-bottom: 15px;
padding-left: 0;

position: relative;
border: 1px dashed #ccc;
background: #f3f3f3;
padding: 20px;
}

.wz-edit-btn-group {
position: absolute;
right: 10px;
bottom: 10px;
}

.wz-page-title {
Expand All @@ -383,6 +393,14 @@ a:hover {
margin: 10px 0 0 10px;
}

#editormd, .dropzone > .SplitPane{
border: 1px dashed #159e92
}

.markdown-body .swagger-ui {
margin-top: 20px;
}

.markdown-body h1 {
font-size: 24px !important;
}
Expand Down
3 changes: 2 additions & 1 deletion public/assets/js/navigator-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ $.wz.navigator_tree = function (left_nav) {
childrenShow(left_nav.children('li'));

left_nav.find('li:not(.wz-has-child)').map(function () {
$(this).prepend('<a class="fa ' + ($(this).data('type') === 'swagger' ? 'fa-code' : 'fa-file-text-o') + ' wz-nav-fold" href="javascript:;"></a>');
var nav_icon = ($(this).data('type') === 'swagger' ? 'fa-code' : ($(this).data('type') === 'markdown' ? 'fa-file-text-o' : 'fa-table'));
$(this).prepend('<a class="fa ' + nav_icon + ' wz-nav-fold" href="javascript:;"></a>');
});

};
Binary file added public/assets/table.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 59a88bd

Please sign in to comment.