banner done
parent
5d93cba509
commit
c6abdf69d3
@ -0,0 +1,83 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Banner;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BannerController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$query = Banner::orderBy('updated_at', 'desc')->paginate();
|
||||
|
||||
return inertia('Banner/Index', [
|
||||
'query' => $query
|
||||
]);
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
return inertia('Banner/Form');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'image' => 'required|image',
|
||||
'title' => 'required|string',
|
||||
'description' => 'required|string',
|
||||
]);
|
||||
|
||||
$file = $request->file('image');
|
||||
$file->store('uploads', 'public');
|
||||
|
||||
Banner::create([
|
||||
'image' => $file->hashName('uploads'),
|
||||
'title' => $request->title,
|
||||
'description' => $request->description,
|
||||
]);
|
||||
|
||||
return redirect()->route('banner.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed saved']);
|
||||
}
|
||||
|
||||
public function edit(Banner $banner)
|
||||
{
|
||||
return inertia('Banner/Form', [
|
||||
'banner' => $banner
|
||||
]);
|
||||
}
|
||||
|
||||
public function update(Request $request, Banner $banner)
|
||||
{
|
||||
$request->validate([
|
||||
'image' => 'nullable|image',
|
||||
'title' => 'required|string',
|
||||
'description' => 'required|string',
|
||||
]);
|
||||
|
||||
if ($request->hasFile('image')) {
|
||||
$file = $request->file('image');
|
||||
$file->store('uploads', 'public');
|
||||
$banner->image = $file->hashName('uploads');
|
||||
}
|
||||
|
||||
$banner->update([
|
||||
'image' => $banner->image,
|
||||
'title' => $request->title,
|
||||
'description' => $request->description,
|
||||
]);
|
||||
|
||||
return redirect()->route('banner.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed updated']);
|
||||
}
|
||||
|
||||
public function destroy(Banner $banner)
|
||||
{
|
||||
$banner->delete();
|
||||
|
||||
return redirect()->route('banner.index')
|
||||
->with('message', ['type' => 'success', 'message' => 'Item has beed deleted']);
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 24 KiB |
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
Binary file not shown.
After Width: | Height: | Size: 261 KiB |
Binary file not shown.
After Width: | Height: | Size: 296 KiB |
@ -0,0 +1,165 @@
|
||||
import { Editor } from '@tinymce/tinymce-react'
|
||||
|
||||
// TinyMCE so the global var exists
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
import tinymce from 'tinymce/tinymce'
|
||||
// DOM model
|
||||
import 'tinymce/models/dom/model'
|
||||
// Theme
|
||||
import 'tinymce/themes/silver'
|
||||
// Toolbar icons
|
||||
import 'tinymce/icons/default'
|
||||
// Editor styles
|
||||
import 'tinymce/skins/ui/oxide/skin.min.css'
|
||||
|
||||
// importing the plugin js.
|
||||
// if you use a plugin that is not listed here the editor will fail to load
|
||||
import 'tinymce/plugins/advlist'
|
||||
import 'tinymce/plugins/anchor'
|
||||
import 'tinymce/plugins/autolink'
|
||||
import 'tinymce/plugins/autoresize'
|
||||
import 'tinymce/plugins/autosave'
|
||||
import 'tinymce/plugins/charmap'
|
||||
import 'tinymce/plugins/code'
|
||||
import 'tinymce/plugins/codesample'
|
||||
import 'tinymce/plugins/directionality'
|
||||
import 'tinymce/plugins/emoticons'
|
||||
import 'tinymce/plugins/fullscreen'
|
||||
import 'tinymce/plugins/help'
|
||||
import 'tinymce/plugins/image'
|
||||
import 'tinymce/plugins/importcss'
|
||||
import 'tinymce/plugins/insertdatetime'
|
||||
import 'tinymce/plugins/link'
|
||||
import 'tinymce/plugins/lists'
|
||||
import 'tinymce/plugins/media'
|
||||
import 'tinymce/plugins/nonbreaking'
|
||||
import 'tinymce/plugins/pagebreak'
|
||||
import 'tinymce/plugins/preview'
|
||||
import 'tinymce/plugins/quickbars'
|
||||
import 'tinymce/plugins/save'
|
||||
import 'tinymce/plugins/searchreplace'
|
||||
import 'tinymce/plugins/table'
|
||||
import 'tinymce/plugins/template'
|
||||
import 'tinymce/plugins/visualblocks'
|
||||
import 'tinymce/plugins/visualchars'
|
||||
import 'tinymce/plugins/wordcount'
|
||||
|
||||
// importing plugin resources
|
||||
import 'tinymce/plugins/emoticons/js/emojis'
|
||||
|
||||
// Content styles, including inline UI like fake cursors
|
||||
/* eslint import/no-webpack-loader-syntax: off */
|
||||
import contentCss from 'tinymce/skins/content/default/content.min.css?inline'
|
||||
import contentUiCss from 'tinymce/skins/ui/oxide/content.min.css?inline'
|
||||
|
||||
import generalCss from '../../css/app.css?inline'
|
||||
|
||||
import { usePage } from '@inertiajs/react'
|
||||
|
||||
export default function BundledEditor(props) {
|
||||
const { init, ...rest } = props
|
||||
const { csrf_token } = usePage().props
|
||||
|
||||
const FilePickerCallback = async (callback, value, meta) => {
|
||||
// Provide file and text for the link dialog
|
||||
const input = document.createElement('input')
|
||||
input.setAttribute('type', 'file')
|
||||
input.setAttribute('accept', 'image/*,video/*')
|
||||
|
||||
input.addEventListener('change', async (e) => {
|
||||
const body = new FormData()
|
||||
body.append('_token', csrf_token)
|
||||
body.append('image', e.target.files[0])
|
||||
|
||||
await fetch(route('post.upload'), {
|
||||
method: 'post',
|
||||
body: body,
|
||||
headers: {
|
||||
'accept-content': 'application/json',
|
||||
'X-CSSRF-TOKEN': csrf_token,
|
||||
},
|
||||
credentials: 'include',
|
||||
})
|
||||
.then((res) => res.json())
|
||||
.then((res) => {
|
||||
callback(res.url, { alt: 'My alt text' })
|
||||
})
|
||||
.catch((err) => {
|
||||
alert(err)
|
||||
})
|
||||
})
|
||||
|
||||
input.click()
|
||||
}
|
||||
|
||||
const ImageUploadHandler = (blobInfo, progress) =>
|
||||
new Promise((resolve, reject) => {
|
||||
const xhr = new XMLHttpRequest()
|
||||
xhr.withCredentials = true
|
||||
xhr.open('POST', route('post.upload'))
|
||||
|
||||
xhr.upload.onprogress = (e) => {
|
||||
progress((e.loaded / e.total) * 100)
|
||||
}
|
||||
|
||||
xhr.onload = () => {
|
||||
if (xhr.status === 403) {
|
||||
reject({
|
||||
message: 'HTTP Error: ' + xhr.status,
|
||||
remove: true,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
if (xhr.status < 200 || xhr.status >= 300) {
|
||||
reject('HTTP Error: ' + xhr.status)
|
||||
return
|
||||
}
|
||||
|
||||
const json = JSON.parse(xhr.responseText)
|
||||
|
||||
if (!json || typeof json.url != 'string') {
|
||||
reject('Invalid JSON: ' + xhr.responseText)
|
||||
return
|
||||
}
|
||||
|
||||
resolve(json.url)
|
||||
}
|
||||
|
||||
xhr.onerror = () => {
|
||||
reject(
|
||||
'Image upload failed due to a XHR Transport error. Code: ' +
|
||||
xhr.status
|
||||
)
|
||||
}
|
||||
|
||||
const formData = new FormData()
|
||||
formData.append('_token', csrf_token)
|
||||
formData.append('image', blobInfo.blob(), blobInfo.filename())
|
||||
|
||||
xhr.send(formData)
|
||||
})
|
||||
|
||||
// note that skin and content_css is disabled to avoid the normal
|
||||
// loading process and is instead loaded as a string via content_style
|
||||
return (
|
||||
<Editor
|
||||
init={{
|
||||
...init,
|
||||
file_picker_callback: FilePickerCallback,
|
||||
images_upload_handler: ImageUploadHandler,
|
||||
promotion: false,
|
||||
image_caption: true,
|
||||
image_advtab: true,
|
||||
object_resizing: true,
|
||||
skin: false,
|
||||
content_css: false,
|
||||
content_style: [contentCss, contentUiCss, generalCss].join(
|
||||
'\n'
|
||||
),
|
||||
importcss_append: true,
|
||||
}}
|
||||
{...rest}
|
||||
/>
|
||||
)
|
||||
}
|
@ -0,0 +1,125 @@
|
||||
import React, { useEffect, Suspense } from 'react'
|
||||
import { isEmpty } from 'lodash'
|
||||
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
||||
import FormInput from '@/Components/FormInput'
|
||||
import Button from '@/Components/Button'
|
||||
import { Head, useForm } from '@inertiajs/react'
|
||||
import FormFile from '@/Components/FormFile'
|
||||
|
||||
const TinyEditor = React.lazy(() => import('@/Components/TinyMCE'))
|
||||
|
||||
export default function Form(props) {
|
||||
const { banner } = props
|
||||
|
||||
const { data, setData, post, processing, errors } = useForm({
|
||||
title: '',
|
||||
description: '',
|
||||
image: '',
|
||||
image_url: '',
|
||||
})
|
||||
|
||||
const handleOnChange = (event) => {
|
||||
setData(
|
||||
event.target.name,
|
||||
event.target.type === 'checkbox'
|
||||
? event.target.checked
|
||||
? 1
|
||||
: 0
|
||||
: event.target.value
|
||||
)
|
||||
}
|
||||
const handleSubmit = () => {
|
||||
if (isEmpty(banner) === false) {
|
||||
post(route('banner.update', banner))
|
||||
return
|
||||
}
|
||||
post(route('banner.store'))
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (isEmpty(banner) === false) {
|
||||
setData({
|
||||
title: banner.title,
|
||||
description: banner.description,
|
||||
image_url: banner.image_url,
|
||||
})
|
||||
}
|
||||
}, [banner])
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
auth={props.auth}
|
||||
errors={props.errors}
|
||||
flash={props.flash}
|
||||
page={'Banner'}
|
||||
action={'Form'}
|
||||
>
|
||||
<Head title="Banner" />
|
||||
|
||||
<div>
|
||||
<div className="mx-auto sm:px-6 lg:px-8">
|
||||
<div className="overflow-hidden p-4 shadow-sm sm:rounded-lg bg-white dark:bg-gray-800 flex flex-col ">
|
||||
<div className="text-xl font-bold mb-4">Banner</div>
|
||||
<FormInput
|
||||
name="title"
|
||||
value={data.title}
|
||||
onChange={handleOnChange}
|
||||
label="Title"
|
||||
error={errors.title}
|
||||
/>
|
||||
<FormFile
|
||||
label={'Image'}
|
||||
onChange={(e) =>
|
||||
setData('image', e.target.files[0])
|
||||
}
|
||||
error={errors.image}
|
||||
preview={
|
||||
isEmpty(data.image_url) === false && (
|
||||
<img
|
||||
src={data.image_url}
|
||||
className="mb-1 h-24 w-full object-cover"
|
||||
alt="preview"
|
||||
/>
|
||||
)
|
||||
}
|
||||
/>
|
||||
|
||||
<div className="py-4">
|
||||
<Suspense fallback={<div>Loading...</div>}>
|
||||
<TinyEditor
|
||||
value={data.description}
|
||||
init={{
|
||||
height: 500,
|
||||
// menubar: false,
|
||||
menubar:
|
||||
'file edit view insert format tools table help',
|
||||
plugins:
|
||||
'preview importcss searchreplace autolink directionality code visualblocks visualchars fullscreen image link media codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount help charmap emoticons',
|
||||
toolbar_mode: 'scrolling',
|
||||
toolbar:
|
||||
'undo redo | insertfile image media link | bold italic underline strikethrough | fontfamily fontsize blocks | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist | forecolor backcolor removeformat | charmap emoticons | fullscreen preview save print | ltr rtl | anchor codesample',
|
||||
}}
|
||||
onEditorChange={(newValue, editor) => {
|
||||
setData(
|
||||
'description',
|
||||
editor.getContent()
|
||||
)
|
||||
}}
|
||||
/>
|
||||
</Suspense>
|
||||
</div>
|
||||
<div className="mt-8">
|
||||
<Button
|
||||
onClick={handleSubmit}
|
||||
processing={processing}
|
||||
>
|
||||
Simpan
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</AuthenticatedLayout>
|
||||
)
|
||||
}
|
@ -0,0 +1,143 @@
|
||||
import React, { useEffect, useState } from 'react'
|
||||
import { Link, router } from '@inertiajs/react'
|
||||
import { usePrevious } from 'react-use'
|
||||
import { Head } from '@inertiajs/react'
|
||||
import { Button, Dropdown } from 'flowbite-react'
|
||||
import { HiPencil, HiTrash } from 'react-icons/hi'
|
||||
import { useModalState } from '@/hooks'
|
||||
|
||||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout'
|
||||
import Pagination from '@/Components/Pagination'
|
||||
import ModalConfirm from '@/Components/ModalConfirm'
|
||||
import { hasPermission } from '@/utils'
|
||||
|
||||
export default function Info(props) {
|
||||
const {
|
||||
query: { links, data },
|
||||
auth,
|
||||
} = props
|
||||
|
||||
const confirmModal = useModalState()
|
||||
|
||||
const handleDeleteClick = (banner) => {
|
||||
confirmModal.setData(banner)
|
||||
confirmModal.toggle()
|
||||
}
|
||||
|
||||
const onDelete = () => {
|
||||
if (confirmModal.data !== null) {
|
||||
router.delete(route('banner.destroy', confirmModal.data.id))
|
||||
}
|
||||
}
|
||||
|
||||
const canCreate = hasPermission(auth, 'create-banner')
|
||||
const canUpdate = hasPermission(auth, 'update-banner')
|
||||
const canDelete = hasPermission(auth, 'delete-banner')
|
||||
|
||||
return (
|
||||
<AuthenticatedLayout
|
||||
auth={props.auth}
|
||||
errors={props.errors}
|
||||
flash={props.flash}
|
||||
page={'Banner'}
|
||||
action={''}
|
||||
>
|
||||
<Head title="Banner" />
|
||||
|
||||
<div>
|
||||
<div className="mx-auto sm:px-6 lg:px-8 ">
|
||||
<div className="p-6 overflow-hidden shadow-sm sm:rounded-lg bg-gray-200 dark:bg-gray-800 space-y-4">
|
||||
<div className="flex justify-between">
|
||||
{canCreate && (
|
||||
<Link href={route('banner.create')}>
|
||||
<Button size="sm">Tambah</Button>
|
||||
</Link>
|
||||
)}
|
||||
</div>
|
||||
<div className="overflow-auto">
|
||||
<div>
|
||||
<table className="w-full text-sm text-left text-gray-500 dark:text-gray-400 mb-4">
|
||||
<thead className="text-xs text-gray-700 uppercase bg-gray-50 dark:bg-gray-700 dark:text-gray-400">
|
||||
<tr>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6"
|
||||
>
|
||||
Judul
|
||||
</th>
|
||||
<th
|
||||
scope="col"
|
||||
className="py-3 px-6 w-1/8"
|
||||
/>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{data.map((banner) => (
|
||||
<tr
|
||||
className="bg-white border-b dark:bg-gray-800 dark:border-gray-700"
|
||||
key={banner.id}
|
||||
>
|
||||
<td
|
||||
scope="row"
|
||||
className="py-4 px-6 font-medium text-gray-900 whitespace-nowrap dark:text-white"
|
||||
>
|
||||
{banner.title}
|
||||
</td>
|
||||
<td className="py-4 px-6 flex justify-end">
|
||||
<Dropdown
|
||||
label={'Opsi'}
|
||||
floatingArrow={true}
|
||||
arrowIcon={true}
|
||||
dismissOnClick={true}
|
||||
size={'sm'}
|
||||
>
|
||||
{canUpdate && (
|
||||
<Dropdown.Item>
|
||||
<Link
|
||||
href={route(
|
||||
'banner.edit',
|
||||
banner
|
||||
)}
|
||||
className="flex space-x-1 items-center"
|
||||
>
|
||||
<HiPencil />
|
||||
<div>
|
||||
Ubah
|
||||
</div>
|
||||
</Link>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
{canDelete && (
|
||||
<Dropdown.Item
|
||||
onClick={() =>
|
||||
handleDeleteClick(
|
||||
banner
|
||||
)
|
||||
}
|
||||
>
|
||||
<div className="flex space-x-1 items-center">
|
||||
<HiTrash />
|
||||
<div>
|
||||
Hapus
|
||||
</div>
|
||||
</div>
|
||||
</Dropdown.Item>
|
||||
)}
|
||||
</Dropdown>
|
||||
</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div className="w-full flex items-center justify-center">
|
||||
<Pagination links={links} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<ModalConfirm modalState={confirmModal} onConfirm={onDelete} />
|
||||
</AuthenticatedLayout>
|
||||
)
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
import React from 'react'
|
||||
import { Head } from '@inertiajs/react'
|
||||
import CustomerLayout from '@/Layouts/CustomerLayout'
|
||||
|
||||
export default function Banner({ banner }) {
|
||||
return (
|
||||
<CustomerLayout>
|
||||
<Head title="Login" />
|
||||
<div className="flex flex-col min-h-[calc(95dvh)] p-4">
|
||||
<img
|
||||
src={banner.image_url}
|
||||
className="object-cover w-full h-32"
|
||||
/>
|
||||
<div className="mt-4 mb-2 text-2xl font-bold">
|
||||
{banner.title}
|
||||
</div>
|
||||
<div dangerouslySetInnerHTML={{ __html: banner.description }} />
|
||||
</div>
|
||||
</CustomerLayout>
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue