131 lines
3.0 KiB
TypeScript
131 lines
3.0 KiB
TypeScript
/// <reference path="../../includes.ts"/>
|
|
/// <reference path="developerPlugin.ts"/>
|
|
module Developer{
|
|
export class OptionsParams{
|
|
public pagerSizeOption = [20,50,100];
|
|
public dataType =null;
|
|
public currentTableSize =20;
|
|
public dataBatch =null;
|
|
public labels={};
|
|
public currentPageNum=1;
|
|
public maxId=0;
|
|
public limit=null;
|
|
public totalSize=null;
|
|
|
|
public createParamData(){
|
|
var extendValue =["cityName", "districtName", "dataVersion", "systemName", "dataYear"];
|
|
var result={
|
|
idIndex: this.maxId,
|
|
dataType: this.dataType,
|
|
submittedBatch: this.dataBatch,
|
|
limit: this.limit
|
|
}
|
|
|
|
angular.forEach(this.labels,(value, key) =>{
|
|
if(extendValue.indexOf(key))
|
|
result[key] = value;
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
public getPageSizeNum(){
|
|
return Math.ceil(this.totalSize/this.currentTableSize);
|
|
|
|
}
|
|
}
|
|
|
|
function createKey(regionalismCode, systemId, version){
|
|
return regionalismCode + "-" + systemId + "-" + version;
|
|
}
|
|
|
|
function populateKey(item){
|
|
var result = item;
|
|
result["_key"] = createKey(item.regionalismCode, item.systemCode, item.dataVersion);
|
|
return result;
|
|
}
|
|
|
|
function populateKeys(items:Array<any>){
|
|
var result =[];
|
|
angular.forEach(items, (item) =>{
|
|
result.push(populateKey(item));
|
|
});
|
|
}
|
|
|
|
function createName(cityName, districtName){
|
|
return cityName + "-" + districtName;
|
|
}
|
|
|
|
function populateName(item){
|
|
var result = item;
|
|
result["name"] = createName(item.cityName, item.districtName);
|
|
return result;
|
|
}
|
|
|
|
function populateNames(items:Array<any>){
|
|
var result = [];
|
|
angular.forEach(items, (item) =>{
|
|
result.push(populateName(item));
|
|
});
|
|
}
|
|
|
|
function createParamData(options: OptionsParams){
|
|
return options.createParamData();
|
|
}
|
|
|
|
export class DataModelService{
|
|
public data = [];
|
|
public paramOptions =new OptionsParams();
|
|
|
|
constructor(){
|
|
console.log(this.paramOptions);
|
|
this.data = this.updataModel(this.paramOptions);
|
|
this.init();
|
|
console.log("running constructor");
|
|
}
|
|
|
|
//更新数据模型
|
|
protected updataModel(paramOptions){
|
|
var result ;
|
|
$.ajax({
|
|
async: false,
|
|
type : "POST",
|
|
url : "/java/console/api/data.json",
|
|
dataType : 'json',
|
|
data: createParamData(paramOptions),
|
|
success : function(data) {
|
|
console.log(paramOptions);
|
|
result = data.data;
|
|
paramOptions.totalSize=data.length;
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
//格式数据模型中的每个单条记录
|
|
public init(){
|
|
populateKeys(this.data);
|
|
populateNames(this.data);
|
|
}
|
|
|
|
//更新用户选择参数
|
|
public updateParamOption(option:string, value:any){
|
|
this.paramOptions[option] = value;
|
|
}
|
|
|
|
//根据key获取用户选择参数
|
|
public getParamOption(key:string){
|
|
return this.paramOptions[key];
|
|
}
|
|
|
|
}
|
|
|
|
//创建数据模型服务
|
|
_module.factory("DataModel", ['$rootScope', '$http', '$location', '$resource', ($rootScope, $http, $location, $resource) => {
|
|
var $scope = new DataModelService();
|
|
console.log($scope.data);
|
|
return $scope;
|
|
}]);
|
|
|
|
|
|
} |