Skip to content

Commit

Permalink
Merge pull request #54 from ecomfe/dev
Browse files Browse the repository at this point in the history
v0.2.3
  • Loading branch information
Justineo committed Dec 29, 2014
2 parents d2fc2fa + 6c71442 commit 4347a04
Show file tree
Hide file tree
Showing 16 changed files with 1,135 additions and 38 deletions.
5 changes: 0 additions & 5 deletions .eslintrc

This file was deleted.

7 changes: 7 additions & 0 deletions .fecsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"eslint": {
"rules": {
"no-else-return": 0
}
}
}
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
* 0.2.3
- 增加 `QuickTip` 控件扩展
- 增加多个 ECharts 图表的控件封装
- `Uploader` 控件现在成功上传的返回值可以为空对象
- `ListAction` 在局部刷新后会触发 `listchange` 事件
- `ListModel` 在局部刷新时会调用一次 `prepare` 方法

* 0.2.2
- 增加了 `SearchTree` 控件
- 增加了 `RichBoxGroup` 控件
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bat-ria",
"version": "0.2.2",
"version": "0.2.3",
"description": "RIA extension for Brand Ads Team",
"main": "main.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/mvc/ListAction.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ define(function (require) {
* 根据新的URL参数刷新列表
*
* @param {er.URL} [url] 新的URL对象,没有时按当前URL刷新
* @fires listchange 跳转后将URL通过事件传递出来,作为child的时候父action可以去修改address bar
* @return {er.Promise} 返回请求的Promise对象
*/
ListAction.prototype.loadList = function (url) {
Expand All @@ -122,6 +123,7 @@ define(function (require) {
return me.model.loadData(url).then(function () {
me.redirect(url, {silent: true});
me.view.refresh();
me.fire('listchange', {url: url});
});
}
};
Expand Down
19 changes: 19 additions & 0 deletions src/mvc/ListModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ define(function (require) {
var util = require('er/util');
var BaseModel = require('./BaseModel');
var batUtil = require('../util');
var Deferred = require('er/Deferred');

/**
* 业务`Model`基类
Expand Down Expand Up @@ -210,7 +211,25 @@ define(function (require) {

return me.listRequester(me.getQuery())
.then(function(data) {
function processError (ex) {
var error = {
success: false,
name: '$prepare',
options: {},
error: ex
};
throw error;
}

me.fill(adaptData(data));

var preparing = me.prepare();
if (Deferred.isPromise(preparing)) {
return preparing.fail(processError);
}
else {
return preparing;
}
});
};

Expand Down
9 changes: 7 additions & 2 deletions src/tpl.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ define(
ToggleButton: './ui',
AuthPanel: './ui',
SearchTree: './ui',
RichBoxGroup: './ui'
RichBoxGroup: './ui',
LineChart: './ui',
PieChart: './ui',
BarChart: './ui'
};

var extensionModulePrefix = {
Expand All @@ -61,7 +64,8 @@ define(
AutoSubmit: './ui/extension',
TableTip: './ui/extension',
TableSubrow: 'esui/extension',
WordCount: './ui/extension'
WordCount: './ui/extension',
QuickTip: './ui/extension'
};

/**
Expand Down Expand Up @@ -132,6 +136,7 @@ define(
* - 对于ESUI扩展,必须写`data-ui-extension-xxx-type="Xxx"`的形式
* - 业务ESUI扩展必须放置在`src/ui/extension`文件夹下
*
* @class tpl
* @singleton
*/
var plugin = {
Expand Down
145 changes: 145 additions & 0 deletions src/ui/BarChart.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
/**
* ADM 2.0
* Copyright 2014 Baidu Inc. All rights reserved.
*
* @ignore
* @file 柱状图封装控件
* @author lixiang([email protected])
* @edit by loutongbing([email protected])
*/

define(
function (require) {
var u = require('underscore');
var lib = require('esui/lib');
var helper = require('esui/controlHelper');
var BaseChart = require('./BaseChart');
require('echarts/chart/bar');
/**
* 控件类
*
* @constructor
* @param {Object} options 初始化参数
*/
function BarChart(options) {
BaseChart.apply(this, arguments);
}

lib.inherits(BarChart, BaseChart);

BarChart.prototype.type = 'BarChart';
BarChart.prototype.styleType = 'Chart';

/**
* 获得提示层的title
*/
BarChart.prototype.getTipTitleHtml = function (params, index) {
var fullText = this.ellipsisToFull[index];
// 截断换行
var length = fullText.length;
var begin = 0;
var lines = [];
while (begin < length) {
lines.push(fullText.substr(begin, 50));
begin = Math.min(begin + 50, length);
}
// 取一个数据做抽取就可以
return lines.join('<br>');
};


/**
* 格式化y轴显示数据
* @param {Object} serie y轴数据
* @return {Object} 返回格式化后的y轴显示所需数据对象
*/
BarChart.prototype.formatYSeriesData = function (serie, index) {
return {
name: serie.label,
type: 'bar',
barWidth: 20,
itemStyle: {
normal: {
color: serie.color
}
},
data: serie.data
};
};


/**
* 重新渲染视图
* 仅当生命周期处于RENDER时,该方法才重新渲染
*
* @param {Array=} 变更过的属性的集合
* @override
*/
BarChart.prototype.repaint = helper.createRepaint(
BaseChart.prototype.repaint
);

/**
* 初始化图表数据
*
* @override
*/
BarChart.prototype.initChartOptions = function () {
return {
tooltip: {
trigger: 'axis',
formatter: lib.bind(this.tipFormatter, this)
},
xAxis: [
{
type: 'category',
axisLine: {
show: true,
lineStyle: {
color: '#333',
width: 1,
style: 'solid'
}
}
}
]
};
};


BarChart.prototype.formatXSeries = function (xSeries) {
// 里面包含用来显示的截断文字,也有全文字,设置个映射,以后用
var ellipsisToFull = [];
var formattedXSeries = [];
u.each(xSeries, function (serie, index) {
ellipsisToFull.push(serie.value);
formattedXSeries.push(serie.text);
});
this.ellipsisToFull = ellipsisToFull;
return formattedXSeries;
};

/**
* 创建Y轴数据
*
* @param {Array} ySeries 序列数据
*
* @return {Array} 坐标集合
* @override
*/
BarChart.prototype.buildYAxis = function (ySeries) {
var yAxis = [];
for (var i = 0; i < ySeries.length; i++) {
var serie = ySeries[i];
// 格式化y轴刻度数据
var formattedYAxisData = this.formatYAxisData(serie);
yAxis.push(formattedYAxisData);
}

return yAxis;
};

require('esui').register(BarChart);
return BarChart;
}
);
Loading

0 comments on commit 4347a04

Please sign in to comment.