You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
3.8 KiB
162 lines
3.8 KiB
/// <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 totalSize=null;
|
|
public priorTableSize = 20;
|
|
|
|
public createParamData(){
|
|
var extendValue =["cityName", "districtName", "dataVersion", "systemName", "dataYear"];
|
|
var result={
|
|
currentPageNum: this.currentPageNum,
|
|
dataType: this.dataType,
|
|
submittedBatch: this.dataBatch,
|
|
limit: this.currentTableSize,
|
|
priorTableSize: this.priorTableSize
|
|
}
|
|
|
|
angular.forEach(this.labels,(value, key) =>{
|
|
if(extendValue.indexOf(key))
|
|
result[key] = value;
|
|
});
|
|
|
|
return result;
|
|
}
|
|
|
|
public getPageSizeNum(){
|
|
var num = Math.ceil(this.totalSize/this.currentTableSize);
|
|
if(num < this.currentPageNum)
|
|
num = this.currentPageNum;
|
|
return num;
|
|
}
|
|
}
|
|
function createLabel(cityName:string, districtName:string, systemName:string, version:string){
|
|
return{
|
|
cityName: cityName,
|
|
districtName: districtName,
|
|
systemName: systemName,
|
|
version: "版本"+version
|
|
}
|
|
}
|
|
|
|
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 populateLabel(item){
|
|
var result = item
|
|
result["labels"] = createLabel(item.cityName, item.districtName, item.systemName, item.dataVersion);
|
|
return result;
|
|
}
|
|
|
|
function populateLabels(items:Array<any>){
|
|
var result = [];
|
|
angular.forEach(items, (item) => {
|
|
result.push(populateLabel(item));
|
|
});
|
|
return result;
|
|
}
|
|
|
|
function populateKeys(items:Array<any>){
|
|
var result =[];
|
|
angular.forEach(items, (item) =>{
|
|
result.push(populateKey(item));
|
|
});
|
|
return result;
|
|
}
|
|
|
|
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));
|
|
});
|
|
return result;
|
|
}
|
|
|
|
function createParamData(options: OptionsParams){
|
|
return options.createParamData();
|
|
}
|
|
|
|
export class DataModelService{
|
|
public data = [];
|
|
public paramOptions = new OptionsParams();
|
|
|
|
constructor(){
|
|
this.updateModel();
|
|
}
|
|
|
|
//更新数据模型
|
|
protected getDataModel(paramOptions){
|
|
var result ;
|
|
$.ajax({
|
|
async: false,
|
|
type : "POST",
|
|
url : "/java/console/api/data.json",
|
|
dataType : 'json',
|
|
data: createParamData(paramOptions),
|
|
success : function(data) {
|
|
result = data.data;
|
|
paramOptions.totalSize=data.length;
|
|
}
|
|
});
|
|
return result;
|
|
}
|
|
|
|
public initParamOptions(){
|
|
this.paramOptions = new OptionsParams();
|
|
}
|
|
|
|
public updateModel(){
|
|
this.data = this.getDataModel(this.paramOptions);
|
|
this.maybeFormat();
|
|
}
|
|
|
|
//格式数据模型中的每个单条记录
|
|
public maybeFormat(){
|
|
this.data = populateKeys(this.data);
|
|
this.data = populateNames(this.data);
|
|
this.data = populateLabels(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();
|
|
return $scope;
|
|
}]);
|
|
|
|
|
|
} |