Skip to content

Commit

Permalink
(unhcr#696) - Cards for ABSY
Browse files Browse the repository at this point in the history
  • Loading branch information
benrudolph committed Nov 19, 2014
1 parent b4088aa commit 1530210
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 54 deletions.
12 changes: 4 additions & 8 deletions app/assets/javascripts/figures/absy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Visio.Figures.Absy extends Visio.Figures.Base


# Conditional Labels
if (self.isPdf and not _.isEmpty self.selected)
if (self.isPdf)
labels = pointContainer.selectAll('.label').data(_.filter([d], (d) => self.isSelected(d.id)))
labels.enter().append('text')
labels.attr('class', 'label')
Expand All @@ -243,7 +243,8 @@ class Visio.Figures.Absy extends Visio.Figures.Base
.attr('text-anchor', 'middle')
.text((d) ->
if self.isPdf
Visio.Utils.numberToLetter(_.indexOf self.selected, "#{d.id}")
idx = self.activeData.chain().pluck('id').map(String).indexOf(String(d.id)).value()
Visio.Utils.numberToLetter idx
else
_.find self.activeData, (a, i) -> a.id == d.id
Visio.Utils.numberToLetter self.activeData.indexOf(a)
Expand Down Expand Up @@ -308,11 +309,6 @@ class Visio.Figures.Absy extends Visio.Figures.Base
.html =>
@yAxisLabel()

# Generate legend view
if @isPdf
@legendView.collection = new @collection.constructor(_.filter(filtered, (d) => self.isSelected(d.id)))


@renderLegend()
@$el.find(".#{@containerClass}").tipsy()

Expand Down Expand Up @@ -340,7 +336,7 @@ class Visio.Figures.Absy extends Visio.Figures.Base
@renderSvgLabels()

isSelected: (id) =>
_.include @selected, "#{id}"
_.chain(@activeData.pluck('id')).map(String).include("#{id}").value()

isQueried: (d) =>
!_.isEmpty(@query) and d.toString().toLowerCase().indexOf(@query.toLowerCase()) != -1
Expand Down
3 changes: 3 additions & 0 deletions app/assets/javascripts/figures/base.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ class Visio.Figures.Base extends Backbone.View
.attr('class', "svg-#{@type.name}-labels svg-labels")
@activeData = new Backbone.Collection()

if @isPdf
@activeData = new Backbone.Collection(config.activeData)

@subscribe() if config.isExport

selectable: true
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/legends/pdf/absy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ class Visio.Legends.AbsyPdf extends Visio.Legends.Base
@

addAll: =>
@collection.each @addOne
@figure.activeData.each @addOne

addOne: (model, idx) =>
view = new Visio.Views.ParameterShowView
filters: @figure.filters
model: model
model: model.get('d')
idx: idx

$legendBody = @$el.find('.legend-body')
Expand Down
3 changes: 2 additions & 1 deletion app/assets/javascripts/manager.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ class Visio.Models.Manager extends Backbone.Model
@set 'strategies', new Visio.Collections.Strategy _state.strategies
@set 'strategy_id', _state.strategy_id
@set 'dashboard', new Visio.Models[_state.dashboardClass](_state.dashboard) if _state.dashboard
@set 'indicator', new Visio.Models.Indicator(_state.indicator) if _state.indicator
return _state
else
return {
Expand All @@ -324,5 +325,5 @@ class Visio.Models.Manager extends Backbone.Model
strategy_id: @get 'strategy_id'
dashboard: @get('dashboard')?.toJSON()
dashboardClass: @get('dashboard')?.name.className
indicator: @get('indicator')?.toJSON()
}

1 change: 0 additions & 1 deletion app/assets/javascripts/mixins/exportable.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Visio.Mixins.Exportable =
config.viewLocation = @viewLocation
config.pdfViewLocation = @pdfViewLocation
config.setupFns = @setupFns
config.activeData = @activeData
config.includeExternalStrategyData = Visio.manager.includeExternalStrategyData()
config

Expand Down
12 changes: 12 additions & 0 deletions app/assets/javascripts/models/figure_filter.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ class Visio.Models.FigureFilter extends Backbone.Model

not @get('values')[datum.get(@id)]

filterOff: (name, opts = {}) ->
return if @get('filterType') != 'checkbox'

_.each _.keys(@get('values')), (key) =>
@get('values')[key] = false

filterOn: (name, opts = {}) ->
return if @get('filterType') != 'checkbox'

_.each _.keys(@get('values')), (key) =>
@get('values')[key] = true

filter: (name, active, opts = {}) ->
return @get('values')[name] unless active?
# Only one can be true for radio type
Expand Down
37 changes: 37 additions & 0 deletions app/assets/javascripts/routers/pdf_router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,42 @@ class Visio.Routers.PdfRouter extends Backbone.Router
for plural, ids of Visio.manager.get('selected')
filterIds["#{Visio.Utils.parameterByPlural(plural).singular}_ids"] = _.keys ids

populationOptions =
add: true
remove: false
type: 'POST'
data:
filter_ids: {}

dashboard = Visio.manager.get 'dashboard'
if dashboard instanceof Visio.Models.Strategy
delete populationOptions.data.filter_ids
populationOptions.data.strategy_id = dashboard.id
else if dashboard instanceof Visio.Models.Operation
populationOptions.data.filter_ids =
operation_ids: [dashboard.id]
ppg_ids: _.keys(dashboard.get('ppg_ids'))
goal_ids: _.keys(dashboard.get('goal_ids'))
problem_objective_ids: _.keys(dashboard.get('problem_objective_ids'))
output_ids: _.keys(dashboard.get('output_ids'))
else if Visio.manager.get('indicator')?
populationOptions.data.filter_ids =
operation_ids: _.keys(dashboard.get('operation_ids'))
ppg_ids: _.keys(dashboard.get('operation_ids'))
goal_ids: _.keys(dashboard.get('goal_ids'))

if Visio.manager.get('indicator').get 'is_performance'
populationOptions.data.filter_ids.problem_objective_ids =
_.keys(dashboard.get('problem_objective_ids'))
populationOptions.data.filter_ids.output_ids = [dashboard.id]
else
populationOptions.data.filter_ids.problem_objective_ids = [dashboard.id]



$.when Visio.manager.get('expenditures').fetch(data :{ filter_ids: filterIds }, type: 'POST'),
Visio.manager.get('budgets').fetch(data :{ filter_ids: filterIds }, type: 'POST'),
Visio.manager.get('populations').fetch(populationOptions),
Visio.manager.get('indicator_data').fetch(data :{ filter_ids: filterIds }, type: 'POST')

absy: ->
Expand All @@ -40,6 +74,9 @@ class Visio.Routers.PdfRouter extends Backbone.Router
top: 70
right: 40

_.each figureConfig.activeData, (d) ->
d.d = new Visio.Models[figureConfig.collectionName](d.d)

Visio.exportModule.set 'figure_config', figureConfig

map: ->
Expand Down
35 changes: 17 additions & 18 deletions app/assets/javascripts/templates/shared/parameter_show.hamlc
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,17 @@
.idx
= Visio.Utils.numberToLetter context.idx

- if context.model.get('country')
.row
.col-md-12
.country-img
%img{
:width => "55",
:height => "55",
:src => "/assets/countries/#{context.model.get('country').iso2.toLowerCase()}/128.png" }

.row.header
.col-sm-6
.col-sm-8
%h5.ui-primary
- if context.model.name == Visio.Parameters.OPERATIONS
= context.model.toString().toUpperCase()
- else
= context.model.toString()

%section
- algorithm = context.filters.get('algorithm').active()
- human = context.filters.get('algorithm').get('human')?[algorithm]
.row
.col-sm-8
.ui-big-number.ui-primary-light
Expand All @@ -45,7 +38,7 @@
.row
.col-sm-12
.bold
Progress Towards Target.
= "Progress towards #{Visio.Utils.humanMetric(context.filters.get('achievement').active())}."

.row
.col-md-12
Expand All @@ -57,12 +50,16 @@
.row
.col-sm-12
.bold
Budget Overview
= human
.row
.col-sm-12
- colSize = Math.floor 12 / context.cols.length
- cloned = new Visio.Collections.FigureFilter(_.map(context.filters.toJSON(), (d) -> $.extend(true, {}, d)))
- _.each context.rows, (scenario, rowNum) ->
.row.table-row
- cloned.get('scenario').filterOff()
- cloned.get('scenario').filter scenario, true

- if rowNum == 0
.col-sm-1.cell  
- else
Expand All @@ -74,23 +71,25 @@

.col-sm-8.zero-padding
- _.each context.cols, (budget, colNum) ->
- cloned.get('budget_type').filterOff()
- cloned.get('budget_type').filter budget, true

- if rowNum == 0
.table-header.cell{ :class => "col-sm-#{colSize}" }
= budget.toLowerCase()
- else
.table-datum.cell{ :class => "col-sm-#{colSize}" }
- budgets = context.model.selectedBudgetData().where({ scenario: scenario, budget_type: budget })
= Visio.Formats.LONG_MONEY((new Visio.Collections.Budget(budgets)).amount())
- result = context.model[algorithm](Visio.manager.year(), cloned)
= Visio.Formats.LONG_MONEY(result)


- if rowNum == 0
.col-sm-3.table-header.table-total.cell
= 'TOTAL BUDGET'
= 'TOTAL'
- else
.col-sm-3.table-datum.table-total.cell
- budgets = context.model.selectedBudgetData(Visio.manager.year(), context.filters).where({ scenario: scenario })
= Visio.Formats.LONG_MONEY((new Visio.Collections.Budget(budgets)).amount())
- result = context.model[algorithm](Visio.manager.year(), context.filters)
= Visio.Formats.LONG_MONEY(result)
.clearfix

- if rowNum == 0
Expand All @@ -100,4 +99,4 @@

.row
.col-sm-12.right-text.bold.cell
= Visio.Formats.LONG_MONEY(context.model.selectedBudget(Visio.manager.year(), context.filters))
= Visio.Formats.LONG_MONEY(context.model[algorithm](Visio.manager.year(), context.filters))
6 changes: 1 addition & 5 deletions app/assets/javascripts/views/shared/export_module.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,7 @@ class Visio.Views.ExportModule extends Backbone.View
$input.prop 'checked', not checked

buildModule: =>
formArray = @$el.find('form').serializeArray()
_.each formArray, (formObj) => @model.set formObj.name, formObj.value

selected = _.map @$el.find('figcaption input[type="checkbox"]:checked'), (ele) -> $(ele).attr('data-id')
@model.get('figure_config').selected = selected
@model.get('figure_config').activeData = @figure.activeData?.toJSON()

onClickEmail: ->
return if @loadingEmail.get 'loading'
Expand Down
2 changes: 0 additions & 2 deletions app/assets/stylesheets/application/global.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3079,7 +3079,6 @@ a {
height: 500px;
header {
@include section;
background-color: $off-white;
padding-top: 15px;
padding-bottom: 15px;
border-bottom: 1px solid $primary;
Expand All @@ -3103,7 +3102,6 @@ a {
}
}


.country-img {
position: relative;
}
Expand Down
1 change: 1 addition & 0 deletions app/assets/stylesheets/application/graphs.scss
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ line {

.point-container {
.label {
fill: $black;
pointer-events: none;
font-weight: bold;
}
Expand Down
15 changes: 2 additions & 13 deletions app/assets/stylesheets/application/pdf.scss
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ body.pdf {
}

.parameter-show {
width: 406px;
width: 380px;
}

.legend-container {
Expand Down Expand Up @@ -255,22 +255,11 @@ body.pdf {
}
}

.parameter-show:nth-of-type(2n+4) {
margin-left: 2px;
}
.parameter-show:nth-of-type(2n+3) {
margin-right: 2px;
}
.parameter-show:nth-of-type(-n+2) {
margin-left: 2px;
}

.idx {
@include number;
width: $parameter-show-idx;
height: $parameter-show-idx;
border-radius: $parameter-show-idx;
border: 2px solid $primary;
color: $black;
text-align: center;
line-height: $parameter-show-idx - 3px;
font-weight: bold;
Expand Down
3 changes: 2 additions & 1 deletion app/assets/stylesheets/shared/mixins.scss
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
position: relative;
margin-left: $parameter-show-padding-horizontal / 2;
margin-right: $parameter-show-padding-horizontal / 2;
border: 1px solid $primary;
padding-top: 0;
}

@mixin section {
padding-left: 15px;
padding-right: 15px;
padding-top: 10px;
padding-bottom: 10px;
}

@mixin number {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/stylesheets/shared/variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ $parameter-slide-width: 345px;
$slider-controls-width: 62px;
$control-radius: 17px;
$parameter-show-idx: 24px;
$parameter-show-padding-horizontal: 50px;
$parameter-show-padding-horizontal: 40px;
$parameter-show-padding-vertical: 30px;
$modal-width: 960px;
$header-button-height: 40px;
Expand Down
4 changes: 2 additions & 2 deletions test/javascripts/pdf_router_test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test 'index - absy aggregated by SO', ->
collection: @sos

config = @absy.config()
config.selected = ["#{@sos.at(0).id}"]
config.activeData = [@sos.at(0).toJSON()]

Visio.router = new Visio.Routers.PdfRouter
selector: $('<div></div>')
Expand Down Expand Up @@ -71,7 +71,7 @@ test 'index - absy', ->
collection: @o

config = @absy.config()
config.selected = [@o.at(0).id]
config.activeData = [@o.at(0).toJSON()]

Visio.router = new Visio.Routers.PdfRouter
selector: $('<div></div>')
Expand Down

0 comments on commit 1530210

Please sign in to comment.