Commit fbc83a726d9d0149815f3a39f6ef7899bec79173

Authored by Igor Kulikov
1 parent 336f0dc0

UI: Fix home page layout.

... ... @@ -17,7 +17,42 @@
17 17 import './home-links.scss';
18 18
19 19 /*@ngInject*/
20   -export default function HomeLinksController($scope, menu) {
  20 +export default function HomeLinksController($scope, $mdMedia, menu) {
  21 +
21 22 var vm = this;
22   - vm.model = menu.getHomeSections();
  23 +
  24 + vm.sectionColspan = sectionColspan;
  25 +
  26 + $scope.$watch(function() { return $mdMedia('lg'); }, function() {
  27 + updateColumnCount();
  28 + });
  29 +
  30 + $scope.$watch(function() { return $mdMedia('gt-lg'); }, function() {
  31 + updateColumnCount();
  32 + });
  33 +
  34 + updateColumnCount();
  35 +
  36 + menu.getHomeSections().then((homeSections) => {
  37 + vm.model = homeSections;
  38 + });
  39 +
  40 + function updateColumnCount() {
  41 + vm.cols = 2;
  42 + if ($mdMedia('lg')) {
  43 + vm.cols = 3;
  44 + }
  45 + if ($mdMedia('gt-lg')) {
  46 + vm.cols = 4;
  47 + }
  48 + }
  49 +
  50 + function sectionColspan(section) {
  51 + var colspan = vm.cols;
  52 + if (section && section.places && section.places.length <= colspan) {
  53 + colspan = section.places.length;
  54 + }
  55 + return colspan;
  56 + }
  57 +
23 58 }
... ...
... ... @@ -15,8 +15,8 @@
15 15 limitations under the License.
16 16
17 17 -->
18   -<md-grid-list class="tb-home-links" md-cols="2" md-cols-lg="3" md-cols-gt-lg="4" md-row-height="280px">
19   - <md-grid-tile md-colspan="2" md-colspan-gt-sm="{{section.places.length}}" ng-repeat="section in vm.model">
  18 +<md-grid-list class="tb-home-links" md-cols="{{vm.cols}}" md-row-height="280px">
  19 + <md-grid-tile md-colspan="2" md-colspan-gt-sm="{{vm.sectionColspan(section)}}" ng-repeat="section in vm.model">
20 20 <md-card style='width: 100%;'>
21 21 <md-card-title>
22 22 <md-card-title-text>
... ... @@ -25,12 +25,12 @@
25 25 </md-card-title>
26 26 <md-card-content>
27 27 <md-grid-list md-row-height="170px" md-cols="{{section.places.length}}" md-cols-gt-md="{{section.places.length}}">
28   - <md-grid-tile class="card-tile" ng-repeat="place in section.places">
29   - <md-button class="tb-card-button md-raised md-primary" layout="column" ui-sref="{{place.state}}">
30   - <md-icon class="material-icons tb-md-96" aria-label="{{place.icon}}">{{place.icon}}</md-icon>
31   - <span translate>{{place.name}}</span>
32   - </md-button>
33   - </md-grid-tile>
  28 + <md-grid-tile class="card-tile" ng-repeat="place in section.places">
  29 + <md-button class="tb-card-button md-raised md-primary" layout="column" ui-sref="{{place.state}}">
  30 + <md-icon class="material-icons tb-md-96" aria-label="{{place.icon}}">{{place.icon}}</md-icon>
  31 + <span translate>{{place.name}}</span>
  32 + </md-button>
  33 + </md-grid-tile>
34 34 </md-grid-list>
35 35 </md-card-content>
36 36 </md-card>
... ...