Merge pull request #1 from BraydonKains/braydon-dev

Merging everything to master for hosting
pull/2/head
BraydonKains 6 years ago committed by GitHub
commit 25095fd234
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

1
.gitignore vendored

@ -1,6 +1,7 @@
vendor/
node_modules/
npm-debug.log
test_responses/
# Laravel 4 specific
bootstrap/compiled.php

Binary file not shown.

@ -3,61 +3,58 @@
namespace App\Http\Controllers;
use App\Post;
use App\Http\Resources\PostCollection;
use Illuminate\Http\Request;
class PostController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
//
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
public function create(Thread $post)
{
//
return view("create_post")->withThread($post);
}
/**
* Store a newly created resource in storage.
* Show the form for editing the specified resource.
*
* @param \Illuminate\Http\Request $request
* @param \App\Post $post
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
public function edit(Post $post)
{
//
return view("edit_post")->withPost($post);
}
/**
* Display the specified resource.
*
* @param \App\Post $post
* @return \Illuminate\Http\Response
* Show the posts for a certain thread.
*
* @param int $thread
*/
public function show(Post $post)
{
//
public function show(int $thread_id) {
$posts = new PostCollection(Post::with("poster")->get()->where("thread_id", $thread_id));
//dd($posts);
return $posts;
}
/**
* Show the form for editing the specified resource.
* Store a newly created resource in storage.
*
* @param \App\Post $post
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function edit(Post $post)
public function store(Request $request)
{
//
$post = new Post;
$post->poster_id = $request->user_id;
$post->content = $request->content;
$post->thread_id = $request->thread_id;
$post->save();
}
/**
@ -69,17 +66,19 @@ class PostController extends Controller
*/
public function update(Request $request, Post $post)
{
//
$post->content = $request->content;
$post->save();
}
/**
* Remove the specified resource from storage.
*
* @param \App\Post $post
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Post $post)
public function destroy(int $id)
{
//
Post::find($id)->delete();
}
}

@ -3,6 +3,7 @@
namespace App\Http\Controllers;
use App\Tag;
use App\Http\Resources\TagCollection;
use Illuminate\Http\Request;
class TagController extends Controller
@ -14,7 +15,7 @@ class TagController extends Controller
*/
public function index()
{
//
return TagCollection(Tag::get());
}
/**
@ -24,40 +25,34 @@ class TagController extends Controller
*/
public function create()
{
//
return view("create_tag");
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
* Show the form for editing the specified resource.
*
* @param \App\Tag $tag
* @return \Illuminate\Http\Response
*/
public function show(Tag $tag)
public function edit(Tag $tag)
{
//
return view("edit_tag");
}
/**
* Show the form for editing the specified resource.
* Store a newly created resource in storage.
*
* @param \App\Tag $tag
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function edit(Tag $tag)
public function store(Request $request)
{
//
$tag = new Tag;
$tag->tag_text = $request->tag_text;
$tag->creator_id = $request->user_id;
$tag->save();
}
/**
@ -69,7 +64,8 @@ class TagController extends Controller
*/
public function update(Request $request, Tag $tag)
{
//
$tag->tag_text = $request->tag_text;
$tag->save();
}
/**
@ -80,6 +76,6 @@ class TagController extends Controller
*/
public function destroy(Tag $tag)
{
//
$tag->delete();
}
}

@ -29,6 +29,26 @@ class ThreadController extends Controller
return view("create_thread");
}
/**
* Show thread view.
*
* @param int $thread
*/
public function view_thread(int $thread_id) {
return view("thread")->with("thread_id", $thread_id);
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function edit(Thread $thread)
{
return view("edit")->withThread($thread);
}
/**
* Store a newly created resource in storage.
*
@ -38,9 +58,9 @@ class ThreadController extends Controller
public function store(Request $request)
{
$thread = new Thread;
//dd($request);
$thread->thread_title = $request->thread_title;
$thread->thread_poster_id = $request->user_id;
$thread->thread_creator_id = $request->user_id;
$thread->save();
}
@ -48,23 +68,15 @@ class ThreadController extends Controller
/**
* Display the specified resource.
*
* @param \App\Thread $thread
* @return \Illuminate\Http\Response
*/
public function show(Thread $thread)
{
return view("thread_view")->withThread($thread);
}
/**
* Show the form for editing the specified resource.
*
* @param \App\Thread $thread
* @param integer $id
* - A thread ID
* @return \Illuminate\Http\Response
*/
public function edit(Thread $thread)
public function show(int $id)
{
//
$selected_thread = new ThreadsCollection(Thread::with("creator")->get()->where("id", $id));
//dd(Thread::with("posts")->get()->where("id", $id));
return Thread::with("creator")->find($id);//$selected_thread;
}
/**
@ -76,17 +88,18 @@ class ThreadController extends Controller
*/
public function update(Request $request, Thread $thread)
{
//
$thread->thread_title = $request->thread_title;
$thread->save();
}
/**
* Remove the specified resource from storage.
*
* @param \App\Thread $thread
* @param int $int
* @return \Illuminate\Http\Response
*/
public function destroy(Thread $thread)
public function destroy(int $id)
{
//
Thread::find($id)->delete();
}
}

@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class PostCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'data' => $this->collection
];
}
}

@ -0,0 +1,21 @@
<?php
namespace App\Http\Resources;
use Illuminate\Http\Resources\Json\ResourceCollection;
class TagCollection extends ResourceCollection
{
/**
* Transform the resource collection into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
"data" => $this->$collection
];
}
}

@ -19,6 +19,9 @@ class ThreadsCollection extends ResourceCollection
];
}
/**
* Deprecated, kept for posterity.
*/
public function getCreators() {
foreach($this->collection as &$t) {
$creator = $t->creator;

@ -26,6 +26,10 @@ class RouteServiceProvider extends ServiceProvider
//
parent::boot();
Route::model('thread', 'App\Thread');
Route::model('post', 'App\Post');
Route::model('tag', 'App\Tag');
}
/**

@ -6,8 +6,6 @@ use Illuminate\Database\Eloquent\Model;
class Thread extends Model
{
private $creator_name;
/**
* Get the creator of the thread.
*/
@ -21,4 +19,11 @@ class Thread extends Model
public function tags() {
return $this->belongsToMany('App\Tag');
}
/**
* Get the posts for the thread.
*/
public function posts() {
return $this->hasMany('App\Post');
}
}

2427
public/js/app.js vendored

File diff suppressed because it is too large Load Diff

@ -0,0 +1,7 @@
Team Members:
Braydon Kains
I declare that all work is done by me, Braydon Kains.
Link to project: http://134.209.48.143
Github repo: https://github.com/BraydonKains/GameGab

@ -20,7 +20,11 @@ window.Vue = require('vue');
// const files = require.context('./', true, /\.vue$/i);
// files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default));
Vue.component('thread-component', require('./components/ThreadComponent.vue').default);
Vue.component('thread-collection', require('./components/ThreadComponent.vue').default);
Vue.component('thread-view', require('./components/ThreadViewComponent.vue').default);
Vue.component('thread-create', require('./components/CreateThreadComponent.vue').default);
Vue.component('post-create', require('./components/CreatePostComponent.vue').default);
Vue.component('gif-select', require('./components/GifSelectComponent.vue').default);
/**
* Next, we will create a fresh Vue application instance and attach it to

@ -0,0 +1,51 @@
<template>
<form @submit.prevent="addPost" class="mb-3">
<h3>
Write Post
</h3>
<div class="form-group">
<textarea type="text" class="form-control" placeholder="Add to your post..." v-model="content"></textarea>
</div>
<div class="form-group">
<gif-select></gif-select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Add</button>
</div>
</form>
</template>
<script>
export default {
props: ['user_id', 'thread_id'],
data() {
return {
content: '',
edit: true
}
},
methods: {
addPost() {
fetch("../api/post/store", {
method: "post",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"content": this.content,
"thread_id": this.thread_id,
"user_id": this.user_id
})
})
.then(res => {
this.content = '';
this.$emit("submitted");
})
.catch(err => console.log(err));
}
}
}
</script>

@ -0,0 +1,48 @@
<template>
<form @submit.prevent="createThread" class="mb-3">
<h3>
Create Thread
</h3>
<div class="form-group">
<input type="text" class="form-control" placeholder="Title" v-model="thread_title">
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">Create Thread</button>
</div>
</form>
</template>
<script>
export default {
props: ['user_id'],
data() {
return {
thread_title: '',
edit: true
}
},
methods: {
createThread() {
fetch("api/thread/store", {
method: "post",
credentials: "same-origin",
headers: {
"Content-Type": "application/json"
},
body: JSON.stringify({
"thread_title": this.thread_title,
"user_id": this.user_id
})
})
.then(res => {
console.log(res);
this.thread_title = '';
this.$emit("submitted");
})
.catch(err => console.log(err));
}
}
}
</script>

@ -1,23 +0,0 @@
<template>
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
<div class="card">
<div class="card-header">Example Component</div>
<div class="card-body">
I'm an example component.
</div>
</div>
</div>
</div>
</div>
</template>
<script>
export default {
mounted() {
console.log('Component mounted.')
}
}
</script>

@ -0,0 +1,63 @@
<style>
.gif-container {
margin-top: 30px;
display: flex;
flex-direction: column;
align-items: center;
}
</style>
<template>
<div>
<input type="text" v-model="search">
<div >
<img v-for="gif in gifs" :src="gif" :key="gif.id">
</div>
</div>
</template>
<script>
export default {
data() {
return {
search: '',
gifs: [],
gif: {
id: ''
}
}
},
methods: {
buildGifs(json) {
this.gifs = json.data
.map(gif => gif.id)
.map(gifId => {
return `https://media.giphy.com/media/${gifId}/giphy.gif`;
});
}
},
watch: {
search: function() {
let apiKey = "nYQNPpAixuVqNPSYjOdhQAAS4oP1Q9rS";
let searchEndPoint = "https://api.giphy.com/v1/gifs/search?";
let limit = 5;
let url = `${searchEndPoint}&api_key=${apiKey}&q=${
this.search
}&limit=${limit}`;
fetch(url)
.then(response => {
return response.json();
})
.then(json => {
this.buildGifs(json);
})
.catch(err => {
console.log(err);
});
}
}
}
</script>

@ -0,0 +1,35 @@
<template>
<div>
<div class="card card-body" v-for="tag in tags" v-bind:key="tag.id">
<p>{{ tag.tag_text }}</p>
</div>
</div>
</template>
<script>
export default {
data() {
return {
tags: [],
tag: {
id: '',
tag_text: ''
}
}
},
created() {
this.fetchTags();
},
methods: {
fetchTags() {
fetch("api/tags")
.then(res => res.json())
.then(res => {
this.tags = res.data;
});
}
}
}
</script>

@ -1,26 +1,46 @@
<template>
<div>
<div style="padding: 10px;">
<thread-create v-if="this.with === 'true'" :user_id="this.user_id" @submitted="fetchThreads"></thread-create>
</div>
<h2>Browse Threads</h2>
<div class="card card-body" v-for="thread in threads" v-bind:key="thread.id">
<p>{{ thread.creator.name }}
<a href="./test/{ {{ thread.id }} }"><h3>{{ thread.thread_title }}</h3></a>
<div>
<label for="search-bar">Search:</label>
<input type="text" name="search-bar" v-model="filter">
</div>
<div v-for="thread in threads" v-bind:key="thread.id">
<div class="card card-body" v-show="!thread.filtered">
<p v-if="thread.creator != null">{{ thread.creator.name }}</p>
<p v-else>[deleted]</p>
<a v-bind:href="'./test/' + thread.id"><h3>{{ thread.thread_title }}</h3></a>
<button v-if="deleteCheck(thread)" v-on:click="destroyThread(thread.id)" class="btn btn-danger">Delete</button>
</div>
</div>
</div>
</template>
<script>
export default {
props: ['user_id', 'with'],
data() {
return {
logged_in: this.user_id,
threads: [],
thread: {
id: '',
thread_title: '',
creator: {
id: '',
name: ''
},
filtered: false
},
thread_id: '',
filter: '',
filtered: [],
filter_flag: false,
scroll_flag: true,
edit: false
}
},
@ -35,7 +55,39 @@ export default {
.then(res => res.json())
.then(res => {
this.threads = res.data;
if(this.scroll_flag) {
window.scrollTo(0,document.body.scrollHeight);
} else this.scroll_flag = true;
});
},
destroyThread(thread_id) {
fetch("api/thread/destroy/" + thread_id)
.then(res => {
this.scroll_flag = false;
this.fetchThreads();
});
},
deleteCheck(thread) {
return thread.creator != null && this.user_id == thread.creator.id;
},
filteredCheck(thread) {
return !this.filtered.include(thread.id);
}
},
watch: {
filter: async function(filter) {
console.log(filter);
Object.keys(this.threads).forEach(thread => {
this.threads[thread].filtered = !this.threads[thread].thread_title.includes(filter);
console.log(this.threads[thread]);
});
await this.$nextTick(function() {
this.$forceUpdate();
});
}
}
}

@ -0,0 +1,80 @@
<template>
<div>
<h2>{{ thread_title }}</h2>
<h3 v-if="creator != null">By {{ creator.name }}</h3>
<h3 v-else>By [deleted]</h3>
<div class="card card-body" v-for="post in posts" v-bind:key="post.id">
<p v-if="post.poster != null">{{ post.poster.name }}</p>
<p v-else>[deleted]</p>
<p>{{ post.content }}</p>
<button v-if="deleteCheck(post)" v-on:click="destroyPost(post.id)" class="btn btn-danger">Delete</button>
</div>
<div style="padding: 10px">
<post-create
v-if="this.with === 'true'"
:user_id="user_id"
:thread_id="thread_id"
@submitted="fetchThread">
</post-create>
</div>
</div>
</template>
<script>
export default {
props: ['user_id', 'thread_id', 'with'],
data() {
return {
id: '',
thread_title: '',
creator: {
name: ''
},
posts: [],
post: {
id: '',
content: '',
poster: {
id: '',
name: ''
}
}
}
},
created() {
this.fetchThread();
},
methods: {
fetchThread() {
fetch("../api/thread/" + this.thread_id)
.then(res => res.json())
.then(res => {
this.id = res.id;
this.thread_title = res.thread_title;
this.creator = res.creator;
})
.catch(err => console.log(err));
fetch("../api/post/thread/" + this.thread_id)
.then(res => res.json())
.then(res => {
this.posts = res.data;
})
.catch(err => console.log(err));;
},
deleteCheck(post) {
return post.poster != null && this.user_id == post.poster.id;
},
destroyPost(post_id) {
fetch("../api/post/destroy/" + post_id)
//.then(res => res.json())
.then(res => {
this.fetchThread();
});
}
}
}
</script>

@ -0,0 +1,9 @@
@extends('layouts.app')
@section('content')
<div class="app">
<div class="container">
<create-thread-form user_id="<?php ?>">
</div>
</div>
@endsection

@ -1,9 +0,0 @@
@extends('layouts.app')
@section('content')
<div id="app">
<div class="container">
<thread-component></thread-component>
</div>
</div>
@endsection

@ -14,7 +14,7 @@
</div>
@endif
You are logged in!
<button onclick="event.preventDefault();document.getElementById('logout-form').submit();" class="btn btn-primary">Logout</button>
</div>
</div>
</div>

@ -39,6 +39,9 @@
<!-- Right Side Of Navbar -->
<ul class="navbar-nav ml-auto">
<!-- Authentication Links -->
<li class="nav-item">
<a class="nav-link" href="{{ route('threads') }}">{{ __('Threads') }}</a>
</li>
@guest
<li class="nav-item">
<a class="nav-link" href="{{ route('login') }}">{{ __('Login') }}</a>
@ -55,12 +58,14 @@
</a>
<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
<a class="dropdown-item" href="{{ route('home') }}">
{{ __('Dashboard') }}
</a>
<a class="dropdown-item" href="{{ route('logout') }}"
onclick="event.preventDefault();
document.getElementById('logout-form').submit();">
{{ __('Logout') }}
</a>
<form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
@csrf
</form>

@ -0,0 +1,13 @@
@extends('layouts.app')
@section('content')
<div class="app">
<div class="container">
@guest
<thread-view thread_id="<?php echo $thread_id; ?>" with="false">
@else
<thread-view user_id="{{ Auth::user()->id }}" thread_id="<?php echo $thread_id; ?>" with="true">
@endguest
</div>
</div>
@endsection

@ -0,0 +1,15 @@
@extends('layouts.app')
@section('content')
<div id="app">
<div class="container">
<div>
@guest
<thread-collection with=false></thread-collection>
@else
<thread-collection user_id="{{ Auth::user()->id }}" with=true></thread-collection>
@endguest
</div>
</div>
</div>
@endsection

@ -17,4 +17,40 @@ Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('threads', 'ThreadController@index');
/**-
* Thread routes
*/
$thread_prefix = "thread";
//Gets
Route::get('threads', 'ThreadController@index');
Route::get($thread_prefix . '/{id}', 'ThreadController@show');
Route::get($thread_prefix . '/destroy/{id}', 'ThreadController@destroy');
//Posts
Route::post($thread_prefix . '/update/{thread}', 'ThreadController@update');
Route::post($thread_prefix . '/store', 'ThreadController@store');
/**
* Post routes
*/
$post_prefix = "post";
//Gets
Route::get($post_prefix . '/thread/{thread_id}', 'PostController@show');
Route::get($post_prefix . '/destroy/{id}', 'PostController@destroy');
//Posts
Route::post($post_prefix . '/update/{post}', 'PostController@update');
Route::post($post_prefix . '/store', 'PostController@store');
/**
* Tag routes
*/
$tag_prefix = "tag";
Route::get('tags', 'TagController@index');
Route::get($tag_prefix . '/{id}', 'TagController@show');
//Posts
Route::post($tag_prefix . '/update/{tag}', 'TagController@update');
Route::post($tag_prefix . '/store', 'TagController@store');
Route::post($tag_prefix . '/destroy/{tag}', 'TagController@destroy');

@ -12,17 +12,15 @@
*/
Route::get('/', function () {
return view('welcome');
return redirect('/threads');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/test', function() {
return view("dashboard");
});
Route::get('/threads', function() {
return view("threads");
})->name('threads');
Route::get('/test/{id}', function() {
return view("thread");
});
Route::get('/test/{thread_id}', "ThreadController@view_thread");

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long
Loading…
Cancel
Save