Tidy up admin cp article related views
This commit is contained in:
parent
abeb5c68f7
commit
7c11b08feb
10 changed files with 14 additions and 14 deletions
141
app/Http/Controllers/Admin/ArticlesController.php
Normal file
141
app/Http/Controllers/Admin/ArticlesController.php
Normal file
|
|
@ -0,0 +1,141 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers\Admin;
|
||||||
|
|
||||||
|
use App\Article;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
use App\Http\Controllers\Controller;
|
||||||
|
|
||||||
|
class ArticlesController extends Controller
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* List the articles that can be edited.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function index()
|
||||||
|
{
|
||||||
|
$posts = Article::select('id', 'title', 'published')->orderBy('id', 'desc')->get();
|
||||||
|
|
||||||
|
return view('admin.articles.list', ['posts' => $posts]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the new article form.
|
||||||
|
*
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function create()
|
||||||
|
{
|
||||||
|
$message = session('message');
|
||||||
|
|
||||||
|
return view('admin.articles.new', ['message' => $message]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process an incoming request for a new article and save it.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function store(Request $request)
|
||||||
|
{
|
||||||
|
$published = $request->input('published');
|
||||||
|
if ($published == null) {
|
||||||
|
$published = '0';
|
||||||
|
}
|
||||||
|
//if a `.md` is attached use that for the main content.
|
||||||
|
$content = null; //set default value
|
||||||
|
if ($request->hasFile('article')) {
|
||||||
|
$file = $request->file('article')->openFile();
|
||||||
|
$content = $file->fread($file->getSize());
|
||||||
|
}
|
||||||
|
$main = $content ?? $request->input('main');
|
||||||
|
try {
|
||||||
|
$article = Article::create(
|
||||||
|
[
|
||||||
|
'url' => $request->input('url'),
|
||||||
|
'title' => $request->input('title'),
|
||||||
|
'main' => $main,
|
||||||
|
'published' => $published,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
$msg = $e->getMessage();
|
||||||
|
$unique = strpos($msg, '1062');
|
||||||
|
if ($unique !== false) {
|
||||||
|
//We've checked for error 1062, i.e. duplicate titleurl
|
||||||
|
return redirect('admin/blog/new')->withInput()->with('message', 'Duplicate title, please change');
|
||||||
|
}
|
||||||
|
//this isn't the error you're looking for
|
||||||
|
throw $e;
|
||||||
|
}
|
||||||
|
|
||||||
|
return view('admin.articles.newsuccess', ['id' => $article->id, 'title' => $article->title]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the edit form for an existing article.
|
||||||
|
*
|
||||||
|
* @param string The article id
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function edit($articleId)
|
||||||
|
{
|
||||||
|
$post = Article::select(
|
||||||
|
'title',
|
||||||
|
'main',
|
||||||
|
'url',
|
||||||
|
'published'
|
||||||
|
)->where('id', $articleId)->get();
|
||||||
|
|
||||||
|
return view('admin.articles.edit', ['id' => $articleId, 'post' => $post]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process an incoming request to edit an article.
|
||||||
|
*
|
||||||
|
* @param \Illuminate\Http\Request $request
|
||||||
|
* @param string
|
||||||
|
* @return \Illuminate|View\Factory view
|
||||||
|
*/
|
||||||
|
public function update(Request $request, $articleId)
|
||||||
|
{
|
||||||
|
$published = $request->input('published');
|
||||||
|
if ($published == null) {
|
||||||
|
$published = '0';
|
||||||
|
}
|
||||||
|
$article = Article::find($articleId);
|
||||||
|
$article->title = $request->input('title');
|
||||||
|
$article->url = $request->input('url');
|
||||||
|
$article->main = $request->input('main');
|
||||||
|
$article->published = $published;
|
||||||
|
$article->save();
|
||||||
|
|
||||||
|
return view('admin.articles.editsuccess', ['id' => $articleId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Show the delete confirmation form for an article.
|
||||||
|
*
|
||||||
|
* @param string The article id
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function delete($articleId)
|
||||||
|
{
|
||||||
|
return view('admin.articles.delete', ['id' => $articleId]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Process a request to delete an aricle.
|
||||||
|
*
|
||||||
|
* @param string The article id
|
||||||
|
* @return \Illuminate\View\Factory view
|
||||||
|
*/
|
||||||
|
public function destroy($articleId)
|
||||||
|
{
|
||||||
|
Article::where('id', $articleId)->delete();
|
||||||
|
|
||||||
|
return view('admin.articles.deletesuccess', ['id' => $articleId]);
|
||||||
|
}
|
||||||
|
}
|
||||||
13
resources/views/admin/articles/delete.blade.php
Normal file
13
resources/views/admin/articles/delete.blade.php
Normal file
|
|
@ -0,0 +1,13 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Delete Article? « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<form action="/admin/blog/delete/{{ $id }}" method="post">
|
||||||
|
<label for="delete">Are you sure you want to delete this post? </label><input type="checkbox" name="delete" id="delete">
|
||||||
|
<br>
|
||||||
|
<input type="submit" id="submit" value="Submit">
|
||||||
|
</form>
|
||||||
|
@stop
|
||||||
9
resources/views/admin/articles/deletesuccess.blade.php
Normal file
9
resources/views/admin/articles/deletesuccess.blade.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Article Deleted « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<p>You have successfully deletd the article with id: {{ $id }}</p>
|
||||||
|
@stop
|
||||||
41
resources/views/admin/articles/edit.blade.php
Normal file
41
resources/views/admin/articles/edit.blade.php
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Edit Article « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<form action="/admin/blog/edit/{{ $id }}" method="post" accept-charset="utf-8">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||||
|
<label for="title">Title (URL):</label>
|
||||||
|
<br>
|
||||||
|
<input type="text" name="title" id="title" value="{!! $post['0']['title'] !!}">
|
||||||
|
<br>
|
||||||
|
<input type="url" name="url" id="url" value="{!! $post['0']['url'] !!}">
|
||||||
|
<br>
|
||||||
|
<label for="main">Main:</label>
|
||||||
|
<br>
|
||||||
|
<textarea name="main" id="main">{{ $post['0']['main'] }}</textarea>
|
||||||
|
<br>
|
||||||
|
<label for="published">Published:</label><input type="checkbox" name="published" value="1"@if($post['0']['published'] == '1') checked="checked"@endif>
|
||||||
|
<br>
|
||||||
|
<input type="submit" name="save" value="Save">
|
||||||
|
</form>
|
||||||
|
<h2>Preview</h2>
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('scripts')
|
||||||
|
@parent
|
||||||
|
<script src="/assets/frontend/marked.min.js"></script>
|
||||||
|
<script>
|
||||||
|
var preview = document.createElement('div');
|
||||||
|
preview.classList.add('preview');
|
||||||
|
var main = document.querySelector('main');
|
||||||
|
main.appendChild(preview);
|
||||||
|
var textarea = document.querySelector('textarea');
|
||||||
|
window.setInterval(function () {
|
||||||
|
var markdown = textarea.value;
|
||||||
|
preview.innerHTML = marked(markdown);
|
||||||
|
}, 5000);
|
||||||
|
</script>
|
||||||
|
@stop
|
||||||
9
resources/views/admin/articles/editsuccess.blade.php
Normal file
9
resources/views/admin/articles/editsuccess.blade.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
Article Successfully Edited « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<p>Successfully edited article with id: {{ $id }}</p>
|
||||||
|
@stop
|
||||||
14
resources/views/admin/articles/list.blade.php
Normal file
14
resources/views/admin/articles/list.blade.php
Normal file
|
|
@ -0,0 +1,14 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
List Articles « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<p>Select article to edit:</p>
|
||||||
|
<ol reversed>
|
||||||
|
@foreach($posts as $post)
|
||||||
|
<li><a href="/admin/blog/edit/{{ $post['id'] }}">{{ $post['title'] }}</a>@if($post['published'] == '0')<span class="notpublished">not published</span>@endif <a href="/admin/blog/delete/{{ $post['id'] }}">Delete?</a>
|
||||||
|
@endforeach
|
||||||
|
</ol>
|
||||||
|
@stop
|
||||||
49
resources/views/admin/articles/new.blade.php
Normal file
49
resources/views/admin/articles/new.blade.php
Normal file
|
|
@ -0,0 +1,49 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
New Article « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
@if(isset($message))<p class="error">{{ $message }}</p>@endif
|
||||||
|
<form action="/admin/blog/new" method="post" accept-charset="utf-8" enctype="multipart/form-data" id="newarticle">
|
||||||
|
<input type="hidden" name="_token" value="{{ csrf_token() }}">
|
||||||
|
<label for="title">Title (URL):</label>
|
||||||
|
<br>
|
||||||
|
<input type="text" name="title" id="title" value="{{ old('title') }}" placeholder="Title here">
|
||||||
|
<br>
|
||||||
|
<input type="text" name="url" id="url" value="{{ old('url') }}" placeholder="Article URL">
|
||||||
|
<br>
|
||||||
|
<label for="main">Main:</label>
|
||||||
|
<br>
|
||||||
|
<textarea name="main" id="main" placeholder="Article here">{{ old('main') }}</textarea>
|
||||||
|
<br>
|
||||||
|
<label for="published">Published:</label><input type="checkbox" name="published" id="published" value="1">
|
||||||
|
<br>
|
||||||
|
<p>Or you can upload an <code>.md</code> file:</p><input type="file" accept=".md" name="article">
|
||||||
|
<br>
|
||||||
|
<button type="submit" name="save">Save</button>
|
||||||
|
</form>
|
||||||
|
<h2>Preview</h2>
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('scripts')
|
||||||
|
@parent
|
||||||
|
<script src="/assets/frontend/marked.min.js"></script>
|
||||||
|
<script>
|
||||||
|
var preview = document.createElement('div');
|
||||||
|
preview.classList.add('preview');
|
||||||
|
var main = document.querySelector('main');
|
||||||
|
main.appendChild(preview);
|
||||||
|
var textarea = document.querySelector('textarea');
|
||||||
|
window.setInterval(function () {
|
||||||
|
var markdown = textarea.value;
|
||||||
|
preview.innerHTML = marked(markdown);
|
||||||
|
}, 5000);
|
||||||
|
</script>
|
||||||
|
<script src="/assets/frontend/store2.min.js"></script>
|
||||||
|
<script src="/assets/frontend/alertify.js"></script>
|
||||||
|
<script src="/assets/js/form-save.js"></script>
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="/assets/frontend/alertify.css">
|
||||||
|
@stop
|
||||||
9
resources/views/admin/articles/newsuccess.blade.php
Normal file
9
resources/views/admin/articles/newsuccess.blade.php
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
@extends('master')
|
||||||
|
|
||||||
|
@section('title')
|
||||||
|
New Article Success « Admin CP
|
||||||
|
@stop
|
||||||
|
|
||||||
|
@section('content')
|
||||||
|
<p>Successfully created article with id: {{ $id }}, title: {{ $title }}</p>
|
||||||
|
@stop
|
||||||
|
|
@ -8,13 +8,13 @@ Admin CP
|
||||||
<h1>Hello {{ $name }}!</h1>
|
<h1>Hello {{ $name }}!</h1>
|
||||||
|
|
||||||
<h2>Articles</h2>
|
<h2>Articles</h2>
|
||||||
<p>You can either <a href="/admin/blog/new">create</a> new blog posts, or <a href="/admin/blog/edit">edit</a> them.<p>
|
<p>You can either <a href="/admin/articles/new">create</a> new blog posts, or <a href="/admin/articles/edit">edit</a> them.<p>
|
||||||
|
|
||||||
<h2>Notes</h2>
|
<h2>Notes</h2>
|
||||||
<p>You can either <a href="/admin/note/new">create</a> new notes, or <a href="/admin/note/edit">edit</a> them.<p>
|
<p>You can either <a href="/admin/notes/new">create</a> new notes, or <a href="/admin/notes/edit">edit</a> them.<p>
|
||||||
|
|
||||||
<h2>Tokens</h2>
|
<h2>Clients</h2>
|
||||||
<p>See all <a href="/admin/tokens">issued tokens</a>.</p>
|
<p>You can either <a href="/admin/clients/new">create</a> new contacts, or <a href="/admin/contacts/edit">edit</a> them.</p>
|
||||||
|
|
||||||
<h2>Contacts</h2>
|
<h2>Contacts</h2>
|
||||||
<p>You can either <a href="/admin/contacts/new">create</a> new contacts, or <a href="/admin/contacts/edit">edit</a> them.</p>
|
<p>You can either <a href="/admin/contacts/new">create</a> new contacts, or <a href="/admin/contacts/edit">edit</a> them.</p>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
//Articles
|
//Articles
|
||||||
Route::group(['prefix' => 'blog'], function () {
|
Route::group(['prefix' => 'articles'], function () {
|
||||||
Route::get('/new', 'ArticlesController@create');
|
Route::get('/new', 'ArticlesController@create');
|
||||||
Route::get('/edit', 'ArticlesController@index');
|
Route::get('/edit', 'ArticlesController@index');
|
||||||
Route::get('/edit/{id}', 'ArticlesController@edit');
|
Route::get('/edit/{id}', 'ArticlesController@edit');
|
||||||
|
|
@ -52,7 +52,7 @@ Route::group(['domain' => config('url.longurl')], function () {
|
||||||
});
|
});
|
||||||
|
|
||||||
//Notes
|
//Notes
|
||||||
Route::group(['prefix' => 'note'], function () {
|
Route::group(['prefix' => 'notes'], function () {
|
||||||
Route::get('/edit', 'NotesController@index');
|
Route::get('/edit', 'NotesController@index');
|
||||||
Route::get('/new', 'NotesController@create');
|
Route::get('/new', 'NotesController@create');
|
||||||
Route::get('/edit/{id}', 'NotesController@edit');
|
Route::get('/edit/{id}', 'NotesController@edit');
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue