-
Notifications
You must be signed in to change notification settings - Fork 3
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
Polymer 2 header migration #702
Changes from 33 commits
9e329b5
b9d9c96
c0be3d4
a1c36b0
8c86a52
ece05d8
dbfcc7e
6274412
9bd0714
3a7ec34
0af70af
4eac699
b32221c
00064f8
41e0706
a40c2b4
d4ea7f7
a65a8e1
b750043
7e71fd5
469d9da
bc62d87
23e90d8
78e2183
d8957d4
9124241
36b000a
e525715
531f2e4
4f18b5b
a5dda14
9b36aad
51c8e4e
5b19af9
6dae1bb
58d5c31
4a7c838
2f11faa
28d53b7
ab8024a
43769d1
c3ee3d8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,4 +2,5 @@ bower_components/ | |
build/ | ||
node_modules/ | ||
.idea/ | ||
.vscode/ | ||
package-lock.json |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,187 @@ | ||
<link rel="import" href="../../../../bower_components/polymer/polymer-element.html"> | ||
<link rel="import" href="../../../../bower_components/polymer/lib/elements/dom-if.html"> | ||
<link rel="import" href="../../../../bower_components/polymer/lib/elements/dom-repeat.html"> | ||
<link rel="import" href="../../../../bower_components/etools-behaviors/etools-mixin-factory.html"> | ||
<link rel="import" href="../../../../bower_components/etools-behaviors/etools-page-refresh-mixin.html"> | ||
<link rel="import" href="../../../../bower_components/paper-dropdown-menu/paper-dropdown-menu.html"> | ||
<link rel="import" href="../../../../bower_components/paper-listbox/paper-listbox.html"> | ||
<link rel="import" href="../../../../bower_components/paper-item/paper-item.html"> | ||
<link rel="import" href="../../../../bower_components/etools-ajax/etools-ajax-request-mixin.html"> | ||
<link rel="import" href="../../endpoints/endpoints-mixin.html"> | ||
<link rel="import" href="../../mixins/event-helper-mixin.html"> | ||
<dom-module id="countries-dropdown"> | ||
<template strip-whitespace> | ||
<style> | ||
|
||
:host { | ||
display: block; | ||
} | ||
|
||
:host(:hover) { | ||
cursor: pointer; | ||
} | ||
|
||
paper-dropdown-menu { | ||
width: 160px; | ||
--paper-input-container-color: var(--countries-dropdown-color); | ||
--paper-input-container-focus-color: var(--countries-dropdown-color); | ||
--paper-input-container-underline: { | ||
display: none; | ||
}; | ||
--paper-input-container-underline-focus: { | ||
display: none; | ||
}; | ||
--paper-input-container-underline-disabled: { | ||
display: none; | ||
}; | ||
|
||
--paper-dropdown-menu-icon: { | ||
color: var(--countries-dropdown-color); | ||
align-self: flex-end; | ||
}; | ||
|
||
--paper-input-container-label: { | ||
top: 4px; | ||
}; | ||
--paper-input-container-input: { | ||
color: var(--countries-dropdown-color); | ||
cursor: pointer; | ||
min-height: 24px; | ||
text-align: right; | ||
}; | ||
--paper-menu-button-dropdown: { | ||
max-height: 380px; | ||
} | ||
} | ||
|
||
paper-item { | ||
font-size: 15px; | ||
white-space: nowrap; | ||
cursor: pointer; | ||
} | ||
|
||
iron-icon { | ||
bottom: 2px; | ||
min-width: 24px; | ||
min-height: 20px; | ||
margin-right: 8px; | ||
} | ||
|
||
paper-item iron-icon { | ||
margin-right: 16px; | ||
} | ||
</style> | ||
|
||
<template is="dom-if" if="[[countrySelectorVisible]]"> | ||
<paper-dropdown-menu id="menu" label="Country" noink no-label-float> | ||
<paper-listbox slot="dropdown-content" | ||
id="countriesListbox" | ||
attr-for-selected="country-id" | ||
selected="[[currentCountry.id]]" | ||
on-iron-select="_countrySelected"> | ||
<template id="repeat" is="dom-repeat" items="[[countries]]"> | ||
<paper-item country-id="[[item.id]]"> | ||
[[item.name]] | ||
</paper-item> | ||
</template> | ||
</paper-listbox> | ||
|
||
</paper-dropdown-menu> | ||
</template> | ||
</template> | ||
|
||
<script> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
'use strict'; | ||
|
||
/** | ||
* @polymer | ||
* @mixinFunction | ||
* @appliesMixin EtoolsLogsMixin | ||
* @appliesMixin EtoolsAjaxRequestMixin | ||
* @appliesMixin EtoolsPageRefreshMixin | ||
* @appliesMixin EtoolsPmpApp.Mixins.Endpoints | ||
* @appliesMixin EtoolsPmpApp.Mixins.EventHelper | ||
*/ | ||
const CountriesDropdownMixin = EtoolsMixinFactory.combineMixins( | ||
[EtoolsLogsMixin, EtoolsAjaxRequestMixin, EtoolsPageRefreshMixin, | ||
EtoolsPmpApp.Mixins.Endpoints, EtoolsPmpApp.Mixins.EventHelper], Polymer.Element); | ||
|
||
/** | ||
* | ||
* @polymer | ||
* @customElement | ||
* @appliesMixin CountriesDropdownMixin | ||
*/ | ||
class CountriesDropdown extends CountriesDropdownMixin { | ||
|
||
static get is() { | ||
return 'countries-dropdown'; | ||
} | ||
|
||
static get properties() { | ||
return { | ||
currentCountry: { | ||
type: Object | ||
}, | ||
countries: { | ||
type: Array, | ||
observer: '_countrySelectorUpdate' | ||
}, | ||
countrySelectorVisible: Boolean | ||
}; | ||
} | ||
|
||
_countrySelected(e) { | ||
if (e.detail.item.countryId !== this.currentCountry.id) { | ||
//send post request to change_coutry endpoint | ||
let selectedCountryId = e.detail.item.countryId; | ||
this._triggerCountryChangeRequest(selectedCountryId); | ||
} | ||
} | ||
|
||
_triggerCountryChangeRequest(countryId) { | ||
let self = this; | ||
this.fireEvent('global-loading', { | ||
message: 'Please wait while country is changing...', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. event There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the event should be defined like this: this.dispatchEvent(new CustomEvent('global-loading', {detail: {message: '...', active: true, loadingSource: '...'}, bubbles: true, composed: true}); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all PR events should be fixed There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
active: true, | ||
loadingSource: 'country-change' | ||
}); | ||
|
||
this.sendRequest({ | ||
endpoint: this.getEndpoint('changeCountry'), | ||
method: 'POST', | ||
body: {country: countryId} | ||
}).then(function(resp) { | ||
self._handleResponse(); | ||
}).catch(function(error) { | ||
self._handleError(error); | ||
}); | ||
} | ||
|
||
_handleResponse() { | ||
this.fireEvent('update-main-path', {path: ''}); | ||
// TODO: refresh method will be removed once etools-ajax v2 is used and the app uses only one dexie db | ||
// TODO for TODO - refresh method is used elsewhere also and the code relies on the redirect trigerred | ||
// by the refresh method | ||
this.refresh(); | ||
} | ||
|
||
_countrySelectorUpdate(countries) { | ||
if (Array.isArray(countries) && (countries.length > 1)) { | ||
this.countrySelectorVisible = true; | ||
} | ||
} | ||
|
||
_handleError(error) { | ||
this.logError('Country change failed!', 'countries-dropdown', error); | ||
// TODO: this should be a larger alert. | ||
this.$.countriesListbox.selected = this.currentCountry; | ||
this.fireEvent('toast', {text: 'Something went wrong changing your workspace. Please try again'}); | ||
this.fireEvent('global-loading', {active: false, loadingSource: 'country-change'}); | ||
} | ||
} | ||
|
||
window.customElements.define(CountriesDropdown.is, CountriesDropdown); | ||
</script> | ||
|
||
</dom-module> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dom-if.html
anddom-repeat.html
import missing