Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor to single page #24

Merged
merged 36 commits into from
Dec 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
c2e67c2
Create index page, set as root and populate with warm-water coral data
Nov 30, 2018
75d0fbb
Create parent vue component and load tabs in
Nov 30, 2018
3096890
Move map into the habitat vue component and pull map data in via pare…
Dec 3, 2018
5c2f7e0
Create column vue component and move into the habitat component along…
Dec 3, 2018
ce96c63
Create row chart vue component and move into the habitat component al…
Dec 3, 2018
721abc6
Add in citations and disclaimer
Dec 3, 2018
ea6bbe6
Add some back end changes for work towards ajax
Dec 6, 2018
50ed3de
Add axios
Dec 17, 2018
8ff042d
Start to build nav component and request for data working
Dec 17, 2018
ec60d02
Get static content loading via ajax
Dec 17, 2018
d018b38
Rename warm water coral yml file to match database and get tabs worki…
Dec 17, 2018
ccc9ded
Make sure column chart has no errors when using ajax data
Dec 17, 2018
3d1cc0c
Get map working with ajaxed data
Dec 17, 2018
ba39d0c
Refactor nav into a vue component that triggers ajax request for new …
Dec 17, 2018
58e34b7
Clean up controller
Dec 17, 2018
9a3901a
Get ScrollMagic working on the row chart with the ajaxed data
Dec 17, 2018
3ec3d7c
Get column chart updating correctly
Dec 17, 2018
79f1a27
Get map layers to change when the habitat has changed
Dec 18, 2018
35cdf8b
Merge branch 'develop' into feature/refactor-to-single-page
Dec 18, 2018
c7df4d0
Remove old routes
Dec 18, 2018
5237250
Rearrange the citations section to match new design
Dec 18, 2018
9c44ef0
Make first paragraph bold in the header
Dec 18, 2018
21ff464
Improve resetting of animation when the habitat changes
Dec 18, 2018
0a94426
Fix up cold corals
Dec 18, 2018
69918a3
Add missing title on the stats panel for the habitat
Dec 18, 2018
6724cd1
return rails generated image paths
Dec 18, 2018
7ba3486
Update styling for nav bar so there isn't a delay in the colour change
Dec 18, 2018
5084198
Try to add in function that makes sure the correct habitat layer is a…
Dec 18, 2018
0490725
Remove redundant files
Dec 18, 2018
0ebf6fa
Move stylesheets about
Dec 18, 2018
63d796a
Pass url hash to backend when calling for habitat data
Dec 19, 2018
3612259
Update hash in the address bar and set the correct item to active
Dec 19, 2018
918bf6e
Add fail safe code to make sure site still works if random hash is in…
Dec 19, 2018
934ae8f
Move nav data to yml file
Dec 19, 2018
d453855
Moved out habitat data to a serializer
Dec 19, 2018
caecdc6
Fix up indentation
Dec 19, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified app/assets/.DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions app/assets/stylesheets/components-vue/_nav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

&__a {
color: $white;
cursor: pointer;
border: solid 1px $nav;
border-radius: $radius-button;
font-size: rem-calc(20);
Expand Down
25 changes: 25 additions & 0 deletions app/assets/stylesheets/components/_smallprint.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//--------------------------------------------------
// smallprint
//--------------------------------------------------
.smallprint {
display: flex;
flex-wrap: wrap;

@include breakpoint($medium) { flex-wrap: nowrap; }

&__citations {
margin: 0 0 rem-calc(20) 0;
width: 100%;

@include breakpoint($medium) {
margin: 0 rem-calc(30) 0 0;
width: 33%;
}
}

&__disclaimer {
width: 100%;

@include breakpoint($medium) { width: 66%; }
}
}
2 changes: 1 addition & 1 deletion app/assets/stylesheets/utilities/_mixins-shared.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
$colour: nth($colours, $index);
$name: nth($names, $index);

.theme--#{$name} & {
&.theme--#{$name} {
border-color: $colour;
color: $colour;
}
Expand Down
63 changes: 11 additions & 52 deletions app/controllers/site_controller.rb
Original file line number Diff line number Diff line change
@@ -1,72 +1,31 @@
class SiteController < ApplicationController
respond_to? :json, :html
before_action :load_habitat
before_action :load_global
before_action :load_charts_data

def warmwater
@data = YAML.load(File.open("#{Rails.root}/lib/data/content/warmwater.yml", 'r'))

@commitments = [
@aichi_targets,
@sdgs,
@data['other_targets']
]
end

def saltmarshes
@data = YAML.load(File.open("#{Rails.root}/lib/data/content/saltmarshes.yml", 'r'))

@commitments = [
@aichi_targets,
@sdgs,
@data['other_targets']
]
end

def mangroves
@data = YAML.load(File.open("#{Rails.root}/lib/data/content/mangroves.yml", 'r'))

@commitments = [
@aichi_targets,
@sdgs,
@data['other_targets']
]
end
def index
@global = YAML.load(File.open("#{Rails.root}/lib/data/content/global.yml", 'r'))

def seagrasses
@data = YAML.load(File.open("#{Rails.root}/lib/data/content/seagrasses.yml", 'r'))
@title = @habitat.title

@commitments = [
@aichi_targets,
@sdgs,
@data['other_targets']
]
end
@nav = @global['nav'].to_json

def coldcorals
@data = YAML.load(File.open("#{Rails.root}/lib/data/content/coldwater.yml", 'r'))
@habitatData = HabitatsSerializer.new(@habitat, @chart_greatest_coverage, @chart_protected_areas, @global).serialize

@commitments = [
@aichi_targets,
@sdgs,
@data['other_targets']
]
respond_to do |format|
format.html
format.json { render json: @habitatData }
end
end

private

def load_habitat
@habitat = Habitat.where(name: action_name).first
@habitat = Habitat.where(name: params['habitat'] || 'warmwater').first
@habitat ||= Habitat.where(name: 'coralreef').first
@habitat_type = @habitat.type
end

def load_global
@global = YAML.load(File.open("#{Rails.root}/lib/data/content/global.yml", 'r'))
@aichi_targets = YAML.load(File.open("#{Rails.root}/lib/data/content/aichi-targets.yml", 'r'))
@sdgs = YAML.load(File.open("#{Rails.root}/lib/data/content/sdgs.yml", 'r'))
end

def load_charts_data
top_five_countries = StaticStat.where(habitat_id: @habitat.id)
.order('total_value DESC')
Expand Down
4 changes: 2 additions & 2 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ def site_description
'Ocean+ Habitats is an evolving tool that provides insight into the known extent, protection and other statistics of ecologically and economically important ocean habitats, such as corals, mangroves, seagrasses and saltmarshes.'
end

def title_meta_tag(page_title)
page_title == nil ? site_title: "#{page_title} | Ocean+ Habitats"
def title_meta_tag
"Ocean+ Habitats"
end

def url_encode text
Expand Down
10 changes: 0 additions & 10 deletions app/helpers/site_helper.rb

This file was deleted.

146 changes: 146 additions & 0 deletions app/javascript/Habitat.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<template>
<div :class="[`theme--${habitat.theme}`]">
<sticky-bar class="nav-wrapper sm-trigger-sticky">
<div class="nav-scrollable sm-target-sticky">
<nav-bar :nav="nav" :default="defaultHabitat" class="gutters flex flex-v-center flex-h-between"></nav-bar>
</div>
</sticky-bar>

<mapbox
:habitatTitle="map.habitatTitle"
:habitatType="map.habitatType"
:theme="map.theme"
:tables="map.tables"
:titleGlobal="map.titleGlobal"
:titleProtected="map.titleProtected"
:percentageGlobal="map.percentageGlobal"
:percentageProtected="map.percentageProtected"
:wmsUrl="map.wmsUrl">
</mapbox>

<chart-column
:habitatTitle="map.habitatTitle"
:habitatType="map.habitatType"
:description="content.top_coverage_description"
:data="habitat.columnChart">
</chart-column>

<chart-row
:description="content.top_protected_description"
:data="habitat.rowChart">
</chart-row>

<section class="section-padding bg--navy white">
<div class="container">
<h3 class="white">Commitments and pledges</h3>
<tabs>
<tab v-for="commitment in habitat.commitments" :id="id(commitment.title)" :title="commitment.title" class="tab__content">
<div v-for="item in commitment.list" class="tab__content-item flex">
<template v-if="item.icon">
<img :src="item.icon" :alt="item.title" class="tab__content-icon">

<p class="tab__content-text" v-html="item.text"></p>
</template>

<template v-else>
<p v-html="item.text"></p>
</template>
</div>
</tab>
</tabs>
</div>
</section>

<section class="section-padding-small">
<div class="container smallprint">
<div class="smallprint__citations">
<h4>Citations</h4>
<p class="text--smallprint" v-html="citation"></p>
</div>

<div class="smallprint__disclaimer">
<h4>Limitations</h4>
<p v-for="p in habitat.disclaimer" class="text--smallprint" v-html="p"></p>
</div>
</div>
</section>
</div>
</template>

<script>
import axios from 'axios'
import { eventHub } from './packs/application.js'

import ChartColumn from './components/chart/ChartColumn.vue'
import ChartRow from './components/chart/ChartRow.vue'
import Tab from './components/tabs/Tab.vue'
import Tabs from './components/tabs/Tabs.vue'
import Mapbox from './components/map/Mapbox.vue'
import NavBar from './components/nav/NavBar.vue'
import StickyBar from './components/sticky/StickyBar.vue'

export default {
name: 'habitat',

components: { ChartColumn, ChartRow, Tab, Tabs, Mapbox, NavBar, StickyBar },

props: {
nav: {
type: Array,
required: true
},
source: {
type: String,
required: true
}
},

data () {
return {
habitat: {},
content: [],
map: {},
citation: ''
}
},

created () {
const hash = window.location.hash.substr(1)

this.defaultHabitat = hash ? hash : 'coralreef'
this.getHabitatData(this.defaultHabitat)

eventHub.$on('changeHabitat', this.getHabitatData)
},

methods: {
id (title) {
return title.toLowerCase().replace(/\s+/g, '')
},

getHabitatData (habitat) {
const csrf = document.querySelectorAll('meta[name="csrf-token"]')[0].getAttribute('content')

axios.defaults.headers.common['X-CSRF-Token'] = csrf
axios.defaults.headers.common['Accept'] = 'application/json'

const data = {
params: {
habitat: habitat
}
}

axios.get(this.source, data)
.then((response) => {
this.habitat = response.data
this.content = this.habitat.content
this.map = this.habitat.map
this.citation = this.habitat.content.citations
})
.catch(function (error) {
console.log(error)
})
}
}
}
</script>
68 changes: 68 additions & 0 deletions app/javascript/components/chart/ChartColumn.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<template>
<section class="bg--grey-light section-padding sm-trigger-column">
<div class="container">
<div class="chart--column">
<div class="chart__content">
<h3 v-if="habitatType == 'points'">Top five countries and territories with the greatest number of records of {{ lowerCaseTitle }}</h3>

<h3 v-else>Top five countries and territories with the greatest coverage of {{ lowerCaseTitle }}</h3>

<p v-for="p in description" v-html="p"></p>
</div>

<div class="chart__scrollable">
<div class="chart__chart center flex flex-h-between">
<div v-for="item in data" class="chart__item">
<div class="chart__bar sm-target-column">
<p class="chart__bar-label sm-target-column no-margin">
{{ item.value }}
<template v-if="habitatType != 'points'">km<sup>2</sup></template>
</p>
<span class="chart__colour sm-target-child-column" :style="{ height: item.percent + '%' }"></span>
</div>
<p class="chart__label bold">{{ item.label }}</p>
</div>
</div>
</div>
</div>
</div>
</section>
</template>

<script>
import ScrollMagic from 'scrollmagic'

export default {
name: 'chart-column',

props: {
habitatType: String,
habitatTitle: String,
description: Array,
data: Array
},

updated () {
if(this.data.length > 0) {
if(this.scene) { this.scene.removeClassToggle(true) }
this.scrollMagicHandlers()
}
},

computed: {
lowerCaseTitle () {
return this.habitatTitle ? this.habitatTitle.toLowerCase() : ''
}
},

methods: {
scrollMagicHandlers () {
let scrollMagicController = new ScrollMagic.Controller()

this.scene = new ScrollMagic.Scene({ triggerElement: '.sm-trigger-column', reverse: false })
.setClassToggle('.sm-target-column .sm-target-child-column, .sm-target-column', 'animate')
.addTo(scrollMagicController)
}
}
}
</script>
Loading