All files / layout/aem-container aem-container.component.ts

100% Statements 19/19
100% Branches 6/6
100% Functions 8/8
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116                                      1x         1x         1x                           1x       1x       1x       15x       15x       1x           78x                 135x                 146x             45x       45x             23x             9x      
/*
 * Copyright 2020 Adobe. All rights reserved.
 * This file is licensed to you under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License. You may obtain a copy
 * of the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under
 * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
 * OF ANY KIND, either express or implied. See the License for the specific language
 * governing permissions and limitations under the License.
 */
 
import { Component, Input } from '@angular/core';
import { Constants } from '../constants';
import { Utils } from '../utils';
 
/**
 * @private
 */
const PLACEHOLDER_CLASS_NAMES = Constants.NEW_SECTION_CLASS_NAMES;
 
/**
 * @private
 */
const PLACEHOLDER_ITEM_NAME = '*';
 
/**
 * @private
 */
const CONTAINER_CLASS_NAMES = 'aem-container';
 
@Component({
  selector: 'aem-container',
  host: {
      '[class]': 'hostClasses',
      '[attr.data-cq-data-path]': 'cqPath'
  },
  templateUrl: './aem-container.component.html'
})
/**
 * The current component provides the base presentational logic common to containers such as a grid or a page.
 * Container have in common the notion of item holders. Items are represented in the model by the fields _:items_ and _:itemsOrder_
 */
export class AEMContainerComponent {
  /**
   * Map of model items included in the current container
   */
  @Input() cqItems;
  /**
   * Array of model item keys
   */
  @Input() cqItemsOrder;
  /**
   * Path to the model associated with the current instance of the component
   */
  @Input() cqPath = '';
  /**
   * Key of the model structure
   */
  @Input() modelName = '';
  /**
   * Class names of the current component
   */
  @Input() classNames: string;
 
  /**
   * Returns weather of not we are in the editor
   */
  get isInEditMode(): boolean {
    return Utils.isInEditor();
  }
 
  /**
   * Returns the aggregated path of this container path and the provided path
   *
   * @param path - the provided path to aggregate with the container path
   */
  getDataPath(path: string): string {
    return this.cqPath ? this.cqPath + '/' + path : path;
  }
 
  /**
   * Returns the item data from the cqModel
   *
   * @param itemKey - the itemKey to look for in the items.
   */
  getItem(itemKey: string): string {
    return this.cqItems && this.cqItems[itemKey];
  }
 
  /**
   * Returns the class names of the container based on the data from the cqModel
   */
  getHostClassNames(): string {
    return CONTAINER_CLASS_NAMES;
  }
 
  get hostClasses(): string {
    return this.getHostClassNames();
  }
 
  /**
   * Returns the placeholder classes
   */
  getPlaceholderClassNames(): string {
    return PLACEHOLDER_CLASS_NAMES;
  }
 
  /**
   * Returns the placeholder path
   */
  get placeholderPath(): string {
    return this.cqPath && this.cqPath + '/' + PLACEHOLDER_ITEM_NAME;
  }
}