projects
/
vchess.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Update colors (unfinished)
[vchess.git]
/
client
/
src
/
views
/
News.vue
diff --git
a/client/src/views/News.vue
b/client/src/views/News.vue
index
ec1517d
..
664b595
100644
(file)
--- a/
client/src/views/News.vue
+++ b/
client/src/views/News.vue
@@
-17,19
+17,22
@@
main
.row
.col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
button#writeNewsBtn(
.row
.col-sm-12.col-md-10.col-md-offset-1.col-lg-8.col-lg-offset-2
button#writeNewsBtn(
- v-if="dev
s.includes(st.user.id)
"
+ v-if="dev
Team
"
@click="showModalNews"
)
| {{ st.tr["Write news"] }}
.news(
v-for="n,idx in newsList"
@click="showModalNews"
)
| {{ st.tr["Write news"] }}
.news(
v-for="n,idx in newsList"
+ :id="'n' + n.id"
:class="{margintop:idx>0}"
)
span.ndt {{ formatDatetime(n.added) }}
:class="{margintop:idx>0}"
)
span.ndt {{ formatDatetime(n.added) }}
-
div(v-if="devs.includes(st.user.id)
")
+
.dev-buttons(v-if="devTeam
")
button(@click="editNews(n)") {{ st.tr["Edit"] }}
button(@click="deleteNews(n)") {{ st.tr["Delete"] }}
button(@click="editNews(n)") {{ st.tr["Edit"] }}
button(@click="deleteNews(n)") {{ st.tr["Delete"] }}
- p(v-html="parseHtml(n.content)")
+ button(@click="gotoPrevNext(n, 1)") {{ st.tr["Previous_n"] }}
+ button(@click="gotoPrevNext(n, -1)") {{ st.tr["Next_n"] }}
+ .news-content(v-html="parseHtml(n.content)")
button#loadMoreBtn(
v-if="hasMore"
@click="loadMore()"
button#loadMoreBtn(
v-if="hasMore"
@click="loadMore()"
@@
-40,21
+43,28
@@
main
<script>
import { store } from "@/store";
import { ajax } from "@/utils/ajax";
<script>
import { store } from "@/store";
import { ajax } from "@/utils/ajax";
+import params from "@/parameters";
import { getDate, getTime } from "@/utils/datetime";
import { processModalClick } from "@/utils/modalClick";
export default {
name: "my-news",
data: function() {
return {
import { getDate, getTime } from "@/utils/datetime";
import { processModalClick } from "@/utils/modalClick";
export default {
name: "my-news",
data: function() {
return {
- devs: [1], //for now the only dev is me
st: store.state,
st: store.state,
- cursor: 0, //ID of last showed news
- hasMore: true, //a priori there could be more news to load
+ // timestamp of oldest showed news:
+ cursor: Number.MAX_SAFE_INTEGER,
+ // hasMore == TRUE: a priori there could be more news to load
+ hasMore: true,
curnews: { id: 0, content: "" },
newsList: [],
infoMsg: ""
};
},
curnews: { id: 0, content: "" },
newsList: [],
infoMsg: ""
};
},
+ computed: {
+ devTeam: function() {
+ return params.devs.includes(this.st.user.id);
+ }
+ },
created: function() {
ajax(
"/news",
created: function() {
ajax(
"/news",
@@
-62,9
+72,11
@@
export default {
{
data: { cursor: this.cursor },
success: (res) => {
{
data: { cursor: this.cursor },
success: (res) => {
- this.newsList = res.newsList.sort((n1, n2) => n2.added - n1.added);
+ // The returned list is sorted from most recent to oldest
+ this.newsList = res.newsList;
const L = res.newsList.length;
const L = res.newsList.length;
- if (L > 0) this.cursor = this.newsList[0].id;
+ if (L > 0) this.cursor = res.newsList[L - 1].added;
+ else this.hasMore = false;
}
}
);
}
}
);
@@
-94,7
+106,7
@@
export default {
},
adjustHeight: function() {
const newsContent = document.getElementById("newsContent");
},
adjustHeight: function() {
const newsContent = document.getElementById("newsContent");
- // https://stackoverflow.com/
questions/995168/textarea-to-resize-based-on-content-length
+ // https://stackoverflow.com/
a/995374
newsContent.style.height = "1px";
newsContent.style.height = 10 + newsContent.scrollHeight + "px";
},
newsContent.style.height = "1px";
newsContent.style.height = 10 + newsContent.scrollHeight + "px";
},
@@
-103,6
+115,10
@@
export default {
this.curnews.content = "";
// No need for added and uid fields: never updated
},
this.curnews.content = "";
// No need for added and uid fields: never updated
},
+ gotoPrevNext: function(n, dir) {
+ document.getElementById("n" + n.id)[
+ (dir < 0 ? "previous" : "next") + "ElementSibling"].scrollIntoView();
+ },
showModalNews: function() {
this.resetCurnews();
window.doClick("modalNews");
showModalNews: function() {
this.resetCurnews();
window.doClick("modalNews");
@@
-118,7
+134,7
@@
export default {
success: (res) => {
if (edit) {
let n = this.newsList.find(n => n.id == this.curnews.id);
success: (res) => {
if (edit) {
let n = this.newsList.find(n => n.id == this.curnews.id);
- if (n) n.content = this.curnews.content;
+ if (
!!
n) n.content = this.curnews.content;
} else {
const newNews = {
content: this.curnews.content,
} else {
const newNews = {
content: this.curnews.content,
@@
-166,10
+182,10
@@
export default {
{
data: { cursor: this.cursor },
success: (res) => {
{
data: { cursor: this.cursor },
success: (res) => {
- if (res.newsList.length > 0) {
+ const L = res.newsList.length;
+ if (L > 0) {
this.newsList = this.newsList.concat(res.newsList);
this.newsList = this.newsList.concat(res.newsList);
- const L = res.newsList.length;
- if (L > 0) this.cursor = res.newsList[L - 1].id;
+ this.cursor = res.newsList[L - 1].added;
} else this.hasMore = false;
}
}
} else this.hasMore = false;
}
}
@@
-205,11
+221,6
@@
span.ndt
color: darkblue
padding: 0 5px 0 var(--universal-margin)
color: darkblue
padding: 0 5px 0 var(--universal-margin)
-.news
- padding-top: 10px
- & > div
- display: inline-block
-
.margintop
margin-top: 25px
border-top: 1px solid grey
.margintop
margin-top: 25px
border-top: 1px solid grey
@@
-217,3
+228,18
@@
span.ndt
.margintop
margin-top: 10px
</style>
.margintop
margin-top: 10px
</style>
+
+<style lang="sass">
+.news
+ padding-top: 10px
+ & > .dev-buttons
+ display: inline-block
+ & > .news-content
+ margin: var(--universal-margin)
+ & > p
+ margin: 10px 0
+ & > br
+ display: block
+ margin-top: 10px
+ content: " "
+</style>