Skip to content

Commit 35e41f5

Browse files
authored
Merge pull request #17 from Kovah/dev
v0.0.2 (Beta 1)
2 parents 357269f + dfccf93 commit 35e41f5

25 files changed

+458
-77
lines changed

LICENSE.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Copyright 2019 Kovah.de
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
4+
documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
5+
rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
6+
persons to whom the Software is furnished to do so, subject to the following conditions:
7+
8+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of
9+
the Software.
10+
11+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12+
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
13+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
14+
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

README.md

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,19 @@
55
<p>&nbsp;</p>
66

77
<p align="center"><b>A small, selfhosted bookmark manager.</b></p>
8-
<p align="center"><b>:warning: This application is still in development and not save to use! :warning:</b></p>
8+
<p align="center"><b>:warning: This application is still in development! :warning:</b></p>
9+
10+
<p align="center">
11+
<a href="https://hub.docker.com/r/linkace/linkace">
12+
<img src="https://img.shields.io/badge/Docker-linkace%2Flinkace-2596EC.svg" alt="Docker Repository">
13+
</a>
14+
<a href="https://github.com/Kovah/LinkAce/releases">
15+
<img src="https://img.shields.io/github/release/kovah/linkace.svg" alt="Latest Release">
16+
</a>
17+
<a href="https://opensource.org/licenses/MIT">
18+
<img src="https://img.shields.io/github/license/kovah/linkace.svg" alt="License">
19+
</a>
20+
</p>
921

1022
<p>&nbsp;</p>
1123

@@ -27,9 +39,9 @@ Now, install all dependencies from inside the PHP container:
2739
$ docker exec linkace-php bash -c "composer install"
2840
```
2941

30-
Last step, compile all assets. You need [Node](https://nodejs.org/en/) with either NPM or [Yarn](https://yarnpkg.com)
42+
Last step: compile all assets. You need [Node](https://nodejs.org/en/) with either NPM or [Yarn](https://yarnpkg.com)
3143
installed.
32-
Node 8 LTS is the minimum version required and recommended to use.
44+
Node 10 LTS is the minimum version required and recommended to use.
3345

3446
```
3547
$ npm install

app/Http/Controllers/App/TrashController.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use App\Http\Controllers\Controller;
66
use App\Models\Category;
77
use App\Models\Link;
8+
use App\Models\Note;
89
use App\Models\Tag;
910
use Illuminate\Http\Request;
1011

@@ -29,10 +30,15 @@ public function index()
2930
->byUser(auth()->id())
3031
->get();
3132

33+
$notes = Note::onlyTrashed()
34+
->byUser(auth()->id())
35+
->get();
36+
3237
return view('actions.trash.index', [
3338
'links' => $links,
3439
'categories' => $categories,
3540
'tags' => $tags,
41+
'notes' => $notes,
3642
]);
3743
}
3844

@@ -63,6 +69,11 @@ public function clearTrash(Request $reques, $model)
6369
->byUser(auth()->id())
6470
->get();
6571
break;
72+
case 'notes':
73+
$entries = Note::onlyTrashed()
74+
->byUser(auth()->id())
75+
->get();
76+
break;
6677
}
6778

6879
if (empty($entries)) {
@@ -72,6 +83,7 @@ public function clearTrash(Request $reques, $model)
7283

7384
foreach ($entries as $entry) {
7485
$entry->forceDelete();
86+
$entry->flushCache();
7587
}
7688

7789
alert(trans('trash.delete_success.' . $model), 'success');
@@ -101,6 +113,9 @@ public function restoreEntry(Request $request, $model, $id)
101113
case 'tag':
102114
$entry = Tag::withTrashed()->find($id);
103115
break;
116+
case 'note':
117+
$entry = Note::withTrashed()->find($id);
118+
break;
104119
}
105120

106121
if (empty($entry)) {
@@ -112,8 +127,9 @@ public function restoreEntry(Request $request, $model, $id)
112127
}
113128

114129
$entry->restore();
130+
$entry->flushCache();
115131

116-
alert(trans('trash.delete_success.' . $model), 'success');
132+
alert(trans('trash.delete_restore.' . $model), 'success');
117133

118134
return redirect()->route('get-trash');
119135
}

app/Http/Controllers/Models/NoteController.php

Lines changed: 70 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,83 +6,115 @@
66
use App\Http\Requests\NoteDeleteRequest;
77
use App\Http\Requests\NoteStoreRequest;
88
use App\Http\Requests\NoteUpdateRequest;
9+
use App\Models\Link;
10+
use App\Models\Note;
911

1012
class NoteController extends Controller
1113
{
12-
/**
13-
* Display a listing of the resource.
14-
*
15-
* @return void
16-
*/
17-
public function index()
18-
{
19-
//
20-
}
21-
22-
/**
23-
* Show the form for creating a new resource.
24-
*
25-
* @return void
26-
*/
27-
public function create()
28-
{
29-
//
30-
}
31-
3214
/**
3315
* Store a newly created resource in storage.
3416
*
3517
* @param NoteStoreRequest $request
36-
* @return void
18+
* @return \Illuminate\Http\RedirectResponse
3719
*/
3820
public function store(NoteStoreRequest $request)
3921
{
40-
//
41-
}
22+
$link = Link::find($request->get('link_id'));
4223

43-
/**
44-
* Display the specified resource.
45-
*
46-
* @param int $id
47-
* @return void
48-
*/
49-
public function show($id)
50-
{
51-
//
24+
if ($link->user_id !== auth()->id()) {
25+
abort(403);
26+
}
27+
28+
$data = $request->except(['_token']);
29+
$data['user_id'] = auth()->id();
30+
31+
$note = Note::create($data);
32+
33+
Note::flushCache();
34+
Link::flushCache();
35+
36+
alert(trans('note.added_successfully'), 'success');
37+
38+
return redirect()->route('links.show', [$link->id]);
5239
}
5340

5441
/**
5542
* Show the form for editing the specified resource.
5643
*
5744
* @param int $id
58-
* @return void
45+
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
5946
*/
6047
public function edit($id)
6148
{
62-
//
49+
$note = Note::find($id);
50+
51+
if (empty($note)) {
52+
abort(404);
53+
}
54+
55+
if ($note->user_id !== auth()->id()) {
56+
abort(404);
57+
}
58+
59+
return view('models.notes.edit')->with('note', $note);
6360
}
6461

6562
/**
6663
* Update the specified resource in storage.
6764
*
6865
* @param NoteUpdateRequest $request
6966
* @param int $id
70-
* @return void
67+
* @return \Illuminate\Http\RedirectResponse
7168
*/
7269
public function update(NoteUpdateRequest $request, $id)
7370
{
74-
//
71+
$note = Note::find($request->get('note_id'));
72+
73+
if (empty($note)) {
74+
abort(404);
75+
}
76+
77+
$data = $request->except(['_token', 'note_id']);
78+
$data['is_private'] = $data['is_private'] ?? false;
79+
80+
$note->update($data);
81+
82+
Note::flushCache();
83+
Link::flushCache();
84+
85+
alert(trans('note.updated_successfully'), 'success');
86+
87+
return redirect()->route('links.show', [$note->link->id]);
7588
}
7689

7790
/**
7891
* Remove the specified resource from storage.
7992
*
8093
* @param NoteDeleteRequest $request
8194
* @param int $id
82-
* @return void
95+
* @return \Illuminate\Http\RedirectResponse
96+
* @throws \Exception
8397
*/
8498
public function destroy(NoteDeleteRequest $request, $id)
8599
{
86-
//
100+
$note = Note::find($id);
101+
102+
if (empty($note)) {
103+
abort(404);
104+
}
105+
106+
if ($note->link->user_id !== auth()->id()) {
107+
abort(404);
108+
}
109+
110+
$link = $note->link->id;
111+
$note->delete();
112+
113+
Note::flushCache();
114+
Link::flushCache();
115+
116+
alert(trans('note.deleted_successfully'), 'success');
117+
118+
return redirect()->route('links.show', [$link]);
87119
}
88120
}

app/Http/Requests/NoteStoreRequest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,9 @@ public function authorize()
2424
public function rules()
2525
{
2626
return [
27+
'link_id' => 'required',
2728
'note' => 'required',
28-
'is_private' => 'required|integer',
29+
'is_private' => 'boolean',
2930
];
3031
}
3132
}

app/Http/Requests/NoteUpdateRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function rules()
4141
return [
4242
'note_id' => 'required',
4343
'note' => 'required',
44-
'is_private' => 'required|integer',
44+
'is_private' => 'boolean',
4545
];
4646
}
4747
}

app/Models/Note.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,4 +73,25 @@ public function link()
7373
{
7474
return $this->belongsTo('App\Models\Link', 'link_id');
7575
}
76+
77+
/*
78+
| ========================================================================
79+
| METHODS
80+
*/
81+
82+
/**
83+
* Output a relative time inside a span with real time information
84+
*
85+
* @return string
86+
*/
87+
public function addedAt()
88+
{
89+
$output = '<time-ago class="cursor-help"';
90+
$output .= ' datetime="' . $this->created_at->toIso8601String() . '"';
91+
$output .= ' title="' . formatDateTime($this->created_at) . '">';
92+
$output .= formatDateTime($this->created_at, true);
93+
$output .= '</time-ago>';
94+
95+
return $output;
96+
}
7697
}

database/migrations/2018_08_22_213055_create_note_tables.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public function up()
1818
$table->integer('user_id')->unsigned();
1919
$table->integer('link_id')->unsigned();
2020
$table->text('note');
21-
$table->boolean('is_private')->default(true);
21+
$table->boolean('is_private')->default(false);
2222
$table->timestamps();
2323
$table->softDeletes();
2424
});

docker-compose.production.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
---
2+
version: "2"
3+
4+
services:
5+
6+
# --- MariaDB
7+
db:
8+
container_name: "linkace-db"
9+
image: bitnami/mariadb:10.1
10+
restart: always
11+
environment:
12+
- MARIADB_ROOT_PASSWORD=${DB_PASSWORD}
13+
- MARIADB_USER=${DB_USERNAME}
14+
- MARIADB_PASSWORD=${DB_PASSWORD}
15+
- MARIADB_DATABASE=${DB_DATABASE}
16+
env_file:
17+
- ./.env
18+
volumes:
19+
- db:/bitnami
20+
21+
# --- LinkAce Image with PHP 7.2
22+
php:
23+
container_name: "linkace-php"
24+
image: linkace/linkace:latest
25+
restart: always
26+
volumes:
27+
- linkace_app:/app
28+
- ./.env:/app/.env:ro
29+
30+
# --- nginx
31+
nginx:
32+
container_name: "linkace-nginx"
33+
image: bitnami/nginx:latest
34+
restart: always
35+
ports:
36+
- "127.0.0.1:80:8085"
37+
depends_on:
38+
- php
39+
env_file:
40+
- ./.env
41+
volumes:
42+
- linkace_app:/app
43+
- site.conf:/opt/bitnami/nginx/conf/vhosts/site.conf:ro
44+
45+
# --- Redis
46+
redis:
47+
container_name: "linkace-redis"
48+
image: bitnami/redis:latest
49+
restart: always
50+
env_file:
51+
- ./.env
52+
environment:
53+
- REDIS_PASSWORD=${REDIS_PASSWORD}
54+
55+
volumes:
56+
linkace_app:
57+
db:
58+
driver: local

0 commit comments

Comments
 (0)