2023-05-02 12:59:30 -05:00
|
|
|
import Helper from '@ember/component/helper';
|
|
|
|
|
import { inject as service } from '@ember/service';
|
|
|
|
|
|
2023-05-03 11:03:48 -05:00
|
|
|
export function indexedDisplayName(intl, translation, array, item) {
|
|
|
|
|
let index = array.indexOf(item) + 1;
|
|
|
|
|
if (index === 0) index = null;
|
|
|
|
|
|
|
|
|
|
return intl.t(translation, { index });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default class IndexedDisplayName extends Helper {
|
2023-05-02 12:59:30 -05:00
|
|
|
// =services
|
|
|
|
|
@service intl;
|
|
|
|
|
|
|
|
|
|
// =methods
|
|
|
|
|
/**
|
|
|
|
|
*
|
|
|
|
|
* @param {string} translation
|
|
|
|
|
* @param {Array} array parent array of item
|
|
|
|
|
* @param {object} item object that you want to find the index of
|
|
|
|
|
* indexOf will not do a deep equality check with item, just if the object exist in the array
|
|
|
|
|
* @returns localized name for resource with indexed position. For example, "Channel 1" for first item in a list.
|
|
|
|
|
*/
|
|
|
|
|
compute([translation, array, item]) {
|
2023-05-03 11:03:48 -05:00
|
|
|
return indexedDisplayName(this.intl, translation, array, item);
|
2023-05-02 12:59:30 -05:00
|
|
|
}
|
|
|
|
|
}
|