Code coverage report for app/pages/phone/phone.controller.js

Statements: 100% (45 / 45)      Branches: 100% (14 / 14)      Functions: 100% (15 / 15)      Lines: 100% (19 / 19)      Ignored: 2 statements, 4 branches     

All files » app/pages/phone/ » phone.controller.js
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                                                                                     
class PhoneController {
    constructor (PhoneAPI, $state, Modal) {
        Object.assign(this, {PhoneAPI, $state, Modal});
 
        this._getPhoneList();
    }
 
    _getPhoneList () {
        this.PhoneAPI.getPhones()
            .then((data) => {
                this.phones = data;
            });
    }
 
    gotoPhoneDetail (phone) {
        this.$state.go('root.layout.phone.detail', {id: phone.id});
    }
 
    deletePhone (phone) {
        this.Modal.open(
            'Are your sure?',
            `All information about [${phone.model}] will be REMOVED!`,
            {ok: 'delete', cancel: 'cancel'},
            (answer) => {
                if (answer) {
                    this._doDelete(phone.id);
                }
            }
        );
    }
 
    _doDelete (id) {
        const self = this;
        this.PhoneAPI.removePhone(id)
            .then(_success)
            .catch(_error);
 
        function _success () {
            self._getPhoneList();
        }
 
        function _error (message) {
            self.Modal.open(
                'Delete phone error',
                message.text,
                {ok: 'OK'},
                (answer) => {
                    if (answer) {
                        self._getPhoneList();
                    }
                }
            );
        }
    }
}
 
PhoneController.$inject = ['PhoneAPI', '$state', 'Modal'];
 
export default PhoneController;