Skip to content
This repository has been archived by the owner on Feb 2, 2018. It is now read-only.

fix #DH176 sidebar navigation on details page to match designs and re… #45

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,14 @@
"lint": "npm run lint:js & npm run lint:sass",
"lint:js": "standard",
"lint:sass": "sass-lint -c .sass-lint.yml 'src/**/*.scss' -v -q",
"develop": "parallel sass:watch js:client:watch js:server:watch",
"develop": "npm run build && parallel sass:watch js:client:watch js:server:watch",
"client:watch": "parallel sass:watch js:client:watch",
"js": "npm run js:client",
"js:client": "webpack",
"js:client:watch": "webpack --watch",
"js:server": "babel src -d build",
"js:server:watch": "nodemon --debug src/server.js",
"sass:watch": "node-sass src/sass/application.scss build/css/application.css --include-path ./node_modules/@uktrade/trade_elements/dist/sass/ --include-path ./node_modules/font-awesome/scss/ -r -w",
"sass:watch": "node-sass src/sass/application.scss build/css/application.css --source-map true --source-map-embed --include-path ./node_modules/@uktrade/trade_elements/dist/sass/ --include-path ./node_modules/font-awesome/scss/ -r -w",
"sass": "node-sass src/sass/application.scss build/css/application.css --include-path ./node_modules/@uktrade/trade_elements/dist/sass/ --include-path ./node_modules/font-awesome/scss/ -x --output-style compressed",
"postinstall": "npm run build",
"sync": "browser-sync start --proxy http://localhost:3000 --files build/css/*.css build/javascripts/*.js"
Expand Down
13 changes: 12 additions & 1 deletion src/controllers/investmentcontroller.js
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,16 @@ function details (req, res) {
advisor: ldetails.referral_source_manager.name
}
const tab = 'summary'

const navItems = [
{label: 'Project', url: `/investment/${sourceId}/details`, tab: 'summary'},
{label: 'Client', url: `/investment/${sourceId}/details`, tab: 'contacts'},
{label: 'Project Team', url: `/investment/${sourceId}/details`, tab: 'interactions'},
{label: 'Interactions', url: `/investment/${sourceId}/details`, tab: 'interactions'},
{label: 'Documents', url: `/investment/${sourceId}/details`, tab: 'interactions'},
{label: 'Evaluation', url: `/investment/${sourceId}/details`, tab: 'interactions'},
{label: 'Audit history', url: `/investment/${sourceId}/details`, tab: 'interactions'}
]
res.render('investment/details',
{
prospectStage,
Expand All @@ -317,7 +327,8 @@ function details (req, res) {
requirementsLabels,
requirementsOrder,
sourceId,
tab
tab,
navItems
})
})
}
Expand Down
108 changes: 108 additions & 0 deletions src/lib/components/TabbedWindow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
// TODO move globally or into the config ? has to be the same as the media query for tablets
const enableIfScreenSmallerThan = 641
const DOM_EL_WINDOW = '.tabbedwindow'
const DOM_EL_TAB = '.tabbedwindow__tab'
const DOM_EL_TAB_ICON = '.tabbedwindow__tab__icon'
const DOM_EL_NAV = '.tabbedwindow__nav'
const DOM_EL_PANE = '.tabbedwindow__pane'

const CSS_CLASS_TAB = `${DOM_EL_TAB}`.replace('.', '')
const CSS_CLASS_TAB_ACTIVE = `${CSS_CLASS_TAB}--active`

let toggleEnabled = null

function TabbedWindow () {
this.toggleEnabled = null
this.domEl = document.querySelector(DOM_EL_WINDOW)
this.domElTabs = [].slice.call(document.querySelectorAll(DOM_EL_TAB))
this.domElNav = document.querySelector(DOM_EL_NAV)
this.domElPane = document.querySelector(DOM_EL_PANE)
}

TabbedWindow.prototype = {
onActiveItems: function () {
return document.querySelectorAll(CSS_CLASS_TAB_ACTIVE)
},
getNonActiveItems: function () {
return this.domElTabs.filter(tab => tab.classList.contains(CSS_CLASS_TAB_ACTIVE) === false)
},
disableActiveLink: function () {
return document.querySelector('.' + CSS_CLASS_TAB_ACTIVE).setAttribute('onclick', 'return false')
},

isItemCollapsed: function (item) {
let chevron = item.querySelector(DOM_EL_TAB_ICON)
return chevron.classList.contains('fa-chevron-down')
},

getActiveItem: function () {
return document.querySelector(`.${CSS_CLASS_TAB_ACTIVE}`)
},

setChevronUp: function (item) {
let chevron = item.querySelector(DOM_EL_TAB_ICON)
chevron.classList.remove('fa-chevron-down')
chevron.className += ' fa-chevron-up '
},

setChevronDown: function (item) {
let chevron = item.querySelector(DOM_EL_TAB_ICON)
chevron.classList.remove('fa-chevron-up')
chevron.className += ' fa-chevron-down '
},

show: function (items) {
[].forEach.call(items, function (a) {
a.style.display = null
})
},

hide: function (items) {
[].forEach.call(items, function (a) {
a.style.display = 'none'
})
},
updateDisplay: function () {
// @TODO stop calling updateDisplay resize
// running dom queries on window resize is bad for performance
// switch to event driven UI (JS Events)
let screenIsSmall = document.documentElement.clientWidth <= enableIfScreenSmallerThan
if (screenIsSmall) {
this.hide(this.getNonActiveItems())
this.toggleEnabled = true
this.disableActiveLink()
} else {
this.setChevronDown(this.getActiveItem())
this.show(this.domElTabs)
this.toggleEnabled = false
}
},
onTabClick: function (e) {
let el = e.target
if (!el.classList.contains(CSS_CLASS_TAB)) {
return
}
if (!this.toggleEnabled) {
return
}
if (this.isItemCollapsed(el)) {
this.setChevronUp(el)
this.show(this.getNonActiveItems())
} else {
this.setChevronDown(el)
this.hide(this.getNonActiveItems())
}
},
init: function () {
// @TODO setinterval on resize callback being fired for performance reason
window.addEventListener('resize', this.updateDisplay.bind(this))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah this is going to hurt - don't we have a debounce function lying around?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i could write one if we don't have one already?

I have just realised we are using lodash already in this project so can use the one included there

window.addEventListener('load', this.updateDisplay.bind(this))
// expand/collapse logic

this.domEl.addEventListener('click', this.onTabClick.bind(this))
console.log('TabWindow initialied!')
console.log(this)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

consoles must die

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

terminated

}
}

module.exports = TabbedWindow
4 changes: 4 additions & 0 deletions src/lib/pages/investment/details.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const TabbedWindow = require('../../components/TabbedWindow')
let oTabbedWindow = new TabbedWindow()

oTabbedWindow.init()
4 changes: 1 addition & 3 deletions src/sass/_leftnav.scss
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
color: $black;
text-decoration: underline;
}

.collapse-filter {
float: right;
color: $white;
Expand Down Expand Up @@ -66,5 +66,3 @@
}

}


1 change: 1 addition & 0 deletions src/sass/application.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ $images-dir: '/images/';
// components
@import 'components/contentheader';
@import 'components/projectstatusbar';
@import 'components/tabbedwindow';
// application specific
@import 'address';
@import 'facets';
Expand Down
4 changes: 2 additions & 2 deletions src/sass/components/_contentheader.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
*/
.contentheader {
@extend .clearfix;
padding:1rem 0;
padding:1.5rem 0;
margin-bottom: 1rem;
border-bottom: 1px solid $grey-2;
}
@media screen and (min-width:$mobile-break-point-max) {
@media screen and (min-width:$mobile-breakpoint-max) {
.contentheader {

clear:both;
Expand Down
9 changes: 6 additions & 3 deletions src/sass/components/_projectstatusbar.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@
*/
.projectstatusbar {
@extend .clearfix;
border-left: 10px solid $grey-2;
padding-left:1rem;
margin: 2rem 0;
&__col {
width:100%;
float:left;
height:60px;
// height:60px;
}

&__col__heading, &__col__value {
Expand All @@ -17,9 +20,9 @@
}
}

@media screen and (min-width:$mobile-break-point-max) {
@media screen and (min-width:$mobile-breakpoint-max) {
.projectstatusbar {
width:$mobile-break-point-max;
width:$mobile-breakpoint-max;
&__col {
width:50%;
}
Expand Down
63 changes: 63 additions & 0 deletions src/sass/components/_tabbedwindow.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
.tabbedwindow {
@extend .clearfix;
// layout
&__nav, &__pane {
float:left;
}
&__nav {
width:25%;
// @extend %site-width-container;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove commented out code if this is a finished file

// @extend %contain-floats;
// clear: both;

}
&__pane {
margin-left:10%;
width:65%;
}
&__tab {
display:block;
height:50px;
padding-left:1rem;
vertical-align:middle;
line-height: 50px;
text-decoration: underline;
position:relative;
&:hover, &:visited {
color:$black;
}
&--active {
background:$govuk-blue;
color:$white;
font-weight: bold;
text-decoration: none;
&:hover, &:visited {
color:$white;
}
& .tabbedwindow__tab__icon {
display: block;
}
@include media (tablet) {
& .tabbedwindow__tab__icon {
display: none;
}
}

}
&__icon {
color:$white;
position: absolute;
right:1rem;
top: 50%;
transform:translate3d(0, -50%, 0);
display: none;
@include media(tablet) {
display: none;
}
// &.fa {
// display:none;
// }
}
}

}
6 changes: 5 additions & 1 deletion src/sass/settings/_variables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,8 @@
* Eventually variables can be split across multiple files
* @type {[type]}
*/
$mobile-break-point-max:320px;

// $tablet-breakpoint: 641px !default;
// $desktop-breakpoint: 769px !default;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gone

$mobile-breakpoint-max:320px;
$tablet-breakpoint-min:640px;
24 changes: 19 additions & 5 deletions src/views/investment/container.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
{% import "macros/trade.html" as trade %}
{% import "./investment_macros.html" as local %}



<section class="projectheader">
<div class="projectoverview">
<h1 class="heading-large">{{ projectTitle | default('Project title goes here') }}</h1>
Expand All @@ -19,7 +17,22 @@ <h1 class="heading-large">{{ projectTitle | default('Project title goes here') }
{% include "./partials/projectstatusbar.html" %}

</section>
<div class="left-nav-container">
<section class="tabbedwindow">
<nav class="tabbedwindow__nav">
{% for tab in navItems %}
<a href="{{tab.url}}" class="tabbedwindow__tab{% if tab.tab == 'summary' %} tabbedwindow__tab--active{% endif %}">
{{tab.label}}
<i class="tabbedwindow__tab__icon collapse-filter-js fa fa-chevron-down"></i>
</a>
{% endfor %}
</nav>
<div class="tabbedwindow__pane">
{% block tabmain%}{% endblock %}
</div>
</section>


{# <div class="left-nav-container">
<div class="left-nav">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

delete commented out code if not here for a good reason

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

gone

<nav>
<div class="{% if tab == 'summary' %}active{% endif %}">
Expand Down Expand Up @@ -57,11 +70,12 @@ <h1 class="heading-large">{{ projectTitle | default('Project title goes here') }
{% block tabmain%}{% endblock %}


</div>
</div> #}
</div>
<script src="/javascripts/common.js"></script>

<script src="/javascripts/leftnav.bundle.js"></script>
{# <script src="/javascripts/leftnav.bundle.js"></script> #}
<script src="/javascripts/investment_details.bundle.js"></script>



Expand Down
3 changes: 2 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module.exports = {
companyedit: './src/forms/companyedit',
investment: './src/forms/investment',
createinvestment: './src/forms/createinvestment',
leftnav: './src/lib/leftnav'
leftnav: './src/lib/leftnav',
investment_details: './src/lib/pages/investment/details'
},
output: {
path: 'build/javascripts',
Expand Down