This repository has been archived by the owner on Feb 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Richard Dern
committed
Oct 10, 2020
1 parent
ca54dd2
commit 908951a
Showing
31 changed files
with
396 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Highlight; | ||
use App\Http\Requests\StoreHighlightRequest; | ||
use Illuminate\Http\Request; | ||
|
||
class HighlightController extends Controller | ||
{ | ||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \App\Http\Requests\StoreHighlightRequest $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(StoreHighlightRequest $request) | ||
{ | ||
$data = $request->validated(); | ||
|
||
$highlight = new Highlight(); | ||
$highlight->user_id = $request->user()->id; | ||
$highlight->expression = $data['expression']; | ||
$highlight->color = $data['color']; | ||
$highlight->save(); | ||
|
||
return $request->user()->highlights()->get(); | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param \App\Http\Requests\StoreHighlightRequest $request | ||
* @param \App\Models\Models\Highlight $highlight | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update(StoreHighlightRequest $request, Highlight $highlight) | ||
{ | ||
if($highlight->user_id !== $request->user()->id) { | ||
abort(404); | ||
} | ||
|
||
$data = $request->validated(); | ||
|
||
$highlight->expression = $data['expression']; | ||
$highlight->color = $data['color']; | ||
$highlight->save(); | ||
|
||
return $request->user()->highlights()->get(); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Models\Models\Hightlight $hightlight | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(Request $request, Highlight $highlight) | ||
{ | ||
if($highlight->user_id !== $request->user()->id) { | ||
abort(404); | ||
} | ||
|
||
$highlight->delete(); | ||
return $request->user()->highlights()->get(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Models\Highlight; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
|
||
class StoreHighlightRequest extends FormRequest | ||
{ | ||
/** | ||
* Determine if the user is authorized to make this request. | ||
* | ||
* @return bool | ||
*/ | ||
public function authorize() | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* Get the validation rules that apply to the request. | ||
* | ||
* @return array | ||
*/ | ||
public function rules() | ||
{ | ||
return [ | ||
'expression' => [ | ||
'required', | ||
], | ||
'color' => [ | ||
'required', | ||
'regex:/^#[0-9a-f]{3,6}$/i', | ||
], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Highlight extends Model | ||
{ | ||
use HasFactory; | ||
|
||
public function user() { | ||
return $this->belongsTo(User::class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
database/migrations/2020_10_09_221017_create_highlights_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateHighlightsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('highlights', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('user_id')->constrained('users')->onDelete('cascade'); | ||
$table->text('expression'); | ||
$table->string('color', 7); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('highlights'); | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/*! | ||
* Vue.js v2.6.12 | ||
* (c) 2014-2020 Evan You | ||
* Released under the MIT License. | ||
*/ | ||
|
||
/*! | ||
* vuex v3.5.1 | ||
* (c) 2020 Evan You | ||
* @license MIT | ||
*/ |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
{ | ||
"/js/app.js": "/js/app.js?id=a60b304e941732617ba9", | ||
"/themes/cyca-dark/theme.css": "/themes/cyca-dark/theme.css?id=413c81b3aca59764179f", | ||
"/themes/cyca-light/theme.css": "/themes/cyca-light/theme.css?id=fdac9b3775b2e876b310", | ||
"/js/import.js": "/js/import.js?id=ae7efb211c07b0292933", | ||
"/js/themes-browser.js": "/js/themes-browser.js?id=62022c1fe5d200aad9b6", | ||
"/js/app.js": "/js/app.js?id=00a40eda576f46e93f37", | ||
"/themes/cyca-dark/theme.css": "/themes/cyca-dark/theme.css?id=f95a8b57b8bf8c8993a9", | ||
"/themes/cyca-light/theme.css": "/themes/cyca-light/theme.css?id=ddebef2fd3bdf5569cbc", | ||
"/js/highlights.js": "/js/highlights.js?id=7d434ae3e4e2f88330f7", | ||
"/js/import.js": "/js/import.js?id=a22d9f4a7e1f9bb440f3", | ||
"/js/themes-browser.js": "/js/themes-browser.js?id=952525d10bea2b418aef", | ||
"/themes/cyca-dark/theme.json": "/themes/cyca-dark/theme.json?id=e6af9f523b70bc467aa4", | ||
"/themes/cyca-light/theme.json": "/themes/cyca-light/theme.json?id=bb59033be8f29999311e" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -61,3 +61,7 @@ | |
|
||
color: theme("colors.feed-item.meta"); | ||
} | ||
|
||
.highlight { | ||
@apply rounded px-1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<template> | ||
<tr> | ||
<td class="w-1/2"><input type="text" class="w-full" v-model="highlight.expression" v-bind:aria-label="__('Expression')" /></td> | ||
<td class="w-1/4"><input type="color" class="w-full" v-model="highlight.color" v-bind:aria-label="__('Color')" /></td> | ||
<td> | ||
<button type="button" class="danger" v-on:click="removeHighlight(highlight.id)" v-bind:title="__('Remove highlight')"> | ||
<svg fill="currentColor" width="16" height="16"> | ||
<use v-bind:xlink:href="icon('trash')" /> | ||
</svg> | ||
</button> | ||
</td> | ||
</tr> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
props: ['highlight'], | ||
mounted: function() { | ||
const self = this; | ||
self.$watch('highlight.expression', self.updateHighlight); | ||
}, | ||
methods: { | ||
updateHighlight: async function() { | ||
const self = this; | ||
const json = await api.put(route('highlight.update', self.highlight), { | ||
expression: self.highlight.expression, | ||
color: self.highlight.color | ||
}); | ||
}, | ||
removeHighlight: function(id) { | ||
this.$emit('destroy', id); | ||
} | ||
} | ||
} | ||
</script> |
Oops, something went wrong.