Skip to content

Instantly share code, notes, and snippets.

@iyhammad
Created January 24, 2016 20:02
Show Gist options
  • Save iyhammad/da1ed67653cadd0afe21 to your computer and use it in GitHub Desktop.
Save iyhammad/da1ed67653cadd0afe21 to your computer and use it in GitHub Desktop.
Sample Angular TypeScript Controller that use ABP generated defenitions
module app.views.employee.basicInformation {
export class add {
private employee: any;
private addEntry: () => void;
private isValidBusinessData: boolean;
private directorates: Array<any>
private departments: Array<any>;
private units: Array<any>;
private locations: Array<any>;
private nationalities: Array<any>;
private genders: Array<any> = [{ id: 1, name: 'Not Specified' }, { id: 2, name: 'Male' }, { id: 3, name: 'Female' }];
private maritalStatuses: Array<any> = [{ id: 1, name: 'Not Specified' }, { id: 2, name: 'Single' }, { id: 3, name: 'Married' }, { id: 4, name: 'Divorced' }];
public static $inject = [
'$stateParams',
'abp.services.hrpayroll.employee',
'$state',
'abp.services.hrpayroll.organization',
'abp.services.hrpayroll.people',
'$scope'
, 'hrPayroll.spinner'
];
constructor($stateParams: angular.ui.IStateParamsService, employeeService: abp.services.hrpayroll.employee, $state: angular.ui.IStateService
, organizationService: abp.services.hrpayroll.organization, peopleService: abp.services.hrpayroll.people, private $scope: angular.IScope, private spinnerService: hrPayroll.spinner)
{
var self = this;
self.employee = {};
self.employee.employeeId = $stateParams['id'];
spinnerService.setBusy(null, organizationService.getActiveLocations({ currentPage: 1, pageSize: 100, searchTerm: "" }).success(function (data) {
self.locations = data.locationsList;
}));
spinnerService.setBusy(null, organizationService.getActiveUnits({ currentPage: 1, pageSize: 100, searchTerm: "" }).success(function (data) {
self.units = data.unitsList;
}));
spinnerService.setBusy(null, organizationService.getActiveDepartments({ orderBy:"Name",currentPage: 1, pageSize: 100, searchTerm: "" }).success(function (data) {
self.departments = data.departmentsList;
}));
spinnerService.setBusy(null, organizationService.getActiveDirectorates({ orderBy: "Name",currentPage: 1, pageSize: 100, searchTerm: "" }).success(function (data) {
self.directorates = data.directoratesList;
}));
spinnerService.setBusy(null, peopleService.getActiveNationalities({ currentPage: 1, pageSize: 100, searchTerm: "" }).success(function (data) {
self.nationalities = data.nationalitiesList;
}));
self.addEntry = function () {
spinnerService.setBusy(null, employeeService.addEmployee({ employee: self.employee }).success(function (data) {
abp.message.success('Employee added successfully', 'Employee');
$state.go('employee.basicInformation', { id:data.employeeId});
}));
}
}
}
}
var myapp = angular.module("app");
myapp.controller('app.views.employee.basicInformation.add', app.views.employee.basicInformation.add);
@RonFrick
Copy link

I got this working as well here is another sample using lambda. This stuff is amazing magic is my eyes. Thank you so much for doing this!!!!!

class CustomerSearch {
static $inject = ['$scope','abp.services.app.customer', '$state'];
customerInput: GetCustomerInput;
loading: boolean;
source: kendo.data.DataSource;
constructor(private $scope: ng.IScope, private customerService: abp.services.app.customer, private $state: ng.ui.IStateService) {
var vm = this;
vm.customerInput = new GetCustomerInput();
}

getCustomers()  {
    this.loading = true;
    this.customerService.getCustomers(this.customerInput)
        .error(() => {
            //could log or tell the user or try to refresh the session since the error is probably a session timeout
        })
        .success((result) => {

            this.loading = false;
            if (result.totalCount == 1)
                this.$state.go('tenant.customerview', { cust_uid: result.items[0].cust_uid });
            else 
                this.source = new kendo.data.DataSource({data: result.items});
        });
};

change (e) {
            console.log(e.dataItem.cust_uid);
            this.$state.go('tenant.customerview', { cust_uid: e.dataItem.cust_uid });
};

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment