Skip to content

Commit

Permalink
insights sharing info and link
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Nov 28, 2015
1 parent 5085cad commit b5c0989
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 37 deletions.
18 changes: 10 additions & 8 deletions app/controllers/Insight.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}
Expand Down
10 changes: 7 additions & 3 deletions app/views/insight/index.scala.html
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -11,10 +11,14 @@
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)"
});
Expand Down
2 changes: 2 additions & 0 deletions modules/insight/src/main/Share.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions public/stylesheets/insight.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 2 additions & 6 deletions ui/insight/src/ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
31 changes: 31 additions & 0 deletions ui/insight/src/info.js
Original file line number Diff line number Diff line change
@@ -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();
}
}
})
]);
};
22 changes: 2 additions & 20 deletions ui/insight/src/view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
]),
Expand Down

0 comments on commit b5c0989

Please sign in to comment.