amdp3-metaforums/Application/Views/index.php

129 lines
4.5 KiB
PHP
Raw Normal View History

2019-11-18 13:33:45 +00:00
<?php
2019-11-19 03:36:39 +00:00
$view->include('layouts/head');
2019-11-18 13:33:45 +00:00
?>
2019-11-20 05:19:02 +00:00
<h1 class="text-4xl py-4">Welcome to metaforums!</h1>
2019-11-19 03:36:39 +00:00
<div id="forumbrowser">
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-left">
<div :id="'group-'+group.id":class="'forumbrowser-item'+(current_group == group.id ? ' selected' : '')" v-for="(group, key) in groups" @click="change_group(group.id)">
2019-11-19 03:36:39 +00:00
{{ group.group_name }}
</div>
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-left">
<div :id="'category-'+category.id":class="'forumbrowser-item'+(current_category == category.id ? ' selected' : '')" v-for="(category, key) in categories" @click="change_category(category.id)">
2019-11-19 03:36:39 +00:00
{{ category.category_name }}
</div>
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-right-table mx-4">
<div v-if="current_category > 0" id="thread-create" class="forumbrowser-right" @click="new_thread(current_category)">
<div class="forumbrowser-right-col"></div>
<div class="forumbrowser-right-col flex-grow">Create New Thread</div>
<div class="forumbrowser-right-col"></div>
<div class="forumbrowser-right-col"></div>
<div class="forumbrowser-right-col"></div>
2019-11-19 03:36:39 +00:00
</div>
2019-11-20 05:19:02 +00:00
<div :id="'thread-'+thread.id":class="'forumbrowser-right'+(current_thread == thread.id ? ' selected' : '')" v-for="(thread, key) in threads" @click="change_thread(thread.id)">
<div class="forumbrowser-right-col">
2019-11-19 03:36:39 +00:00
<p v-if="thread.is_hot">[HOT]</p>
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-right-col flex-grow">
2019-11-19 03:36:39 +00:00
{{ thread.title }}
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-right-col">
2019-11-19 03:36:39 +00:00
by {{ thread.author_model.username }}
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-right-col">
2019-11-19 03:36:39 +00:00
View: {{ thread.view_count }} Post count: {{ thread.post_count }}
</div>
2019-11-20 05:19:02 +00:00
<div class="forumbrowser-right-col">
2019-11-19 03:36:39 +00:00
{{ thread.last_reply }}
</div>
</div>
</div>
</div>
<div id="threadreader">
</div>
<div id="editor">
</div>
<script>
var selectapp = new Vue({
el: "#forumbrowser",
data: {
groups: <?php echo json_encode($groups); ?>,
current_group: 0,
current_category: 0,
current_thread: 0,
current_group: <?php echo isset($group) ? $group->id : 0; ?>,
current_category: <?php echo isset($category) ? $category->id : 0;?>,
current_thread: <?php echo isset($thread) ? $thread->id : 0; ?>,
categories: [],
threads: [],
},
methods: {
change_category(id) {
2019-11-20 05:19:02 +00:00
this.current_category = id;
this.threads = [];
this.current_thread = 0;
$("#threadreader").html("");
$("#editor").html("");
window.history.pushState('category-'+id,'','<?php echo $root; ?>/?category='+id+window.location.hash);
2019-11-19 03:36:39 +00:00
$.ajax("<?php echo $root; ?>/api/get_threads?id="+id)
.done(function(data) {
this.threads = data;
}.bind(this));
},
change_group(id) {
2019-11-20 05:19:02 +00:00
this.current_group = id;
this.categories = [];
this.current_category = 0;
this.threads = [];
this.current_thread = 0;
$("#threadreader").html("");
$("#editor").html("");
window.history.pushState('group-'+id,'','<?php echo $root; ?>/?group='+id+window.location.hash);
2019-11-19 03:36:39 +00:00
$.ajax("<?php echo $root; ?>/api/get_categories?id="+id)
.done(function(data) {
this.categories = data;
}.bind(this));
},
change_thread(id) {
2019-11-20 05:19:02 +00:00
if(this.current_thread != 0 && this.current_thread != id) {
window.location.hash = "#";
} else if(this.current_thread == id) return;
this.current_thread = id;
$("#editor").html("");
window.history.pushState('thread-'+id,'','<?php echo $root; ?>/?thread='+id+window.location.hash);
2019-11-19 03:36:39 +00:00
$.ajax("<?php echo $root; ?>/thread?id="+id)
.done(function(data) {
$("#threadreader").html(data);
2019-11-20 05:19:02 +00:00
window.location.hash = window.location.hash;
2019-11-19 03:36:39 +00:00
}.bind(this));
},
new_thread(id) {
2019-11-20 05:19:02 +00:00
this.current_thread = 0;
2019-11-19 03:36:39 +00:00
$.ajax("<?php echo $root; ?>/thread/editor?category="+id)
.done(function(data) {
$("#threadreader").html("");
$("#editor").html(data);
}.bind(this));
},
},
2019-11-20 05:19:02 +00:00
mounted: function() {
<?php
if(isset($group)) {
echo "this.change_group(".$group->id.")\n";
}
if(isset($category)) {
echo "this.change_category(".$category->id.")\n";
}
if(isset($thread)) {
echo "this.change_thread(".$thread->id.")\n";
}
?>
2019-11-19 03:36:39 +00:00
}
});
2019-11-20 05:19:02 +00:00
2019-11-19 03:36:39 +00:00
</script>
2019-11-18 13:33:45 +00:00
<?php
2019-11-19 03:36:39 +00:00
$view->include('layouts/foot');
2019-11-18 13:33:45 +00:00
?>