insights sharing info and link

pull/1262/head
Thibault Duplessis 2015-11-28 23:04:10 +07:00
parent 5085cadf1d
commit b5c098982b
7 changed files with 57 additions and 37 deletions

View File

@ -28,14 +28,16 @@ object Insight extends LilaController {
env.api userStatus user flatMap {
case NoGame => Ok(html.insight.noGame(user)).fuccess
case Empty => Ok(html.insight.empty(user)).fuccess
case s => env.api count user map { nbGames =>
Ok(html.insight.index(
u = user,
nbGames = nbGames,
ui = env.jsonView.stringifiedUi,
question = env.jsonView.question(metric, dimension, filters),
stale = s == Stale))
}
case s => for {
nbGames <- env.api count user
prefId <- env.share getPrefId user
} yield Ok(html.insight.index(
u = user,
nbGames = nbGames,
prefId = prefId,
ui = env.jsonView.stringifiedUi,
question = env.jsonView.question(metric, dimension, filters),
stale = s == Stale))
}
}
}

View File

@ -1,4 +1,4 @@
@(u: User, nbGames: Int, ui: String, question: play.api.libs.json.JsObject, stale: Boolean)(implicit ctx: Context)
@(u: User, nbGames: Int, prefId: Int, ui: String, question: play.api.libs.json.JsObject, stale: Boolean)(implicit ctx: Context)
@moreJs = {
@highchartsLatestTag
@ -11,10 +11,14 @@ LichessInsight(document.getElementById('insight'), {
ui: @Html(ui),
initialQuestion: @Html(toJson(question)),
i18n: @jsI18n(),
userId: "@u.id",
username: "@u.username",
myUserId: @Html(ctx.userId.fold("null")(id => s""""$id"""")),
user: {
id: "@u.id",
name: "@u.username",
nbGames: @nbGames,
stale: @stale,
shareId: @prefId
},
pageUrl: "@routes.Insight.index(u.username)",
postUrl: "@routes.Insight.json(u.username)"
});

View File

@ -7,6 +7,8 @@ final class Share(
getPref: String => Fu[Pref],
areFriends: (String, String) => Fu[Boolean]) {
def getPrefId(insighted: User) = getPref(insighted.id) map (_.insightShare)
def grant(insighted: User, to: Option[User]): Fu[Boolean] = getPref(insighted.id) flatMap { pref =>
pref.insightShare match {
case _ if to.contains(insighted) => fuccess(true)

View File

@ -146,6 +146,9 @@
#insight .info.box .insight-stale button {
width: 100%;
}
#insight .info .share a {
text-decoration: underline;
}
#insight .help.box {
margin-top: 20px;

View File

@ -4,12 +4,8 @@ var throttle = require('./throttle');
module.exports = function(env) {
this.ui = env.ui;
this.user = {
id: env.userId,
name: env.username,
nbGames: env.nbGames,
stale: env.stale
};
this.user = env.user;
this.own = env.myUserId === this.user.id;
var findMetric = function(key) {
return this.ui.metrics.filter(function(x) {

View File

@ -0,0 +1,31 @@
var m = require('mithril');
var shareStates = ["nobody", "friends only", "everybody"];
module.exports = function(ctrl) {
var shareText = 'Shared with ' + shareStates[ctrl.user.shareId] + '.';
return m('div.info.box', [
m('div.top', [
m('a.username.user_link.ulpt', {
href: '/@/' + ctrl.user.name
}, ctrl.user.name)
]),
m('div.content', [
m('p', 'Insights over ' + ctrl.user.nbGames + ' rated games.'),
m('p.share', ctrl.own ? m('a', {
href: '/account/preferences/privacy',
target: '_blank'
}, shareText) : shareText)
]),
m('div.refresh', {
config: function(e, isUpdate) {
if (isUpdate) return;
var $ref = $('.insight-stale');
if ($ref.length) {
$(e).html($ref.show());
lichess.refreshInsightForm();
}
}
})
]);
};

View File

@ -4,32 +4,14 @@ var filters = require('./filters');
var chart = require('./chart');
var table = require('./table');
var help = require('./help');
var info = require('./info');
module.exports = function(ctrl) {
return m('div', {
class: ctrl.vm.loading ? 'loading' : 'ready'
}, [
m('div.left', [
m('div.info.box', [
m('div.top', [
m('a.username.user_link.ulpt', {
href: '/@/' + ctrl.user.name
}, ctrl.user.name)
]),
m('div.content', [
m('p.nbGames', 'Insights over ' + ctrl.user.nbGames + ' rated games.'),
m('div.refresh', {
config: function(e, isUpdate) {
if (isUpdate) return;
var $ref = $('.insight-stale');
if ($ref.length) {
$(e).html($ref.show());
lichess.refreshInsightForm();
}
}
})
])
]),
info(ctrl),
filters(ctrl),
help(ctrl)
]),