add expand years

This commit is contained in:
Shaun Chyxion 2017-07-23 23:29:36 +08:00
parent 532e3148b2
commit 09befa7c9c
8 changed files with 149 additions and 21 deletions

View File

@ -6,20 +6,17 @@ import lombok.extern.slf4j.Slf4j;
import me.chyxion.tigon.mybatis.Search;
import me.chyxion.tigon.model.ViewModel;
import org.apache.commons.csv.CSVRecord;
import com.pudonghot.ambition.crm.model.*;
import me.chyxion.tigon.model.ListResult;
import org.apache.commons.lang3.StringUtils;
import com.pudonghot.ambition.crm.model.User;
import org.springframework.stereotype.Service;
import com.pudonghot.ambition.crm.util.CSVUtils;
import com.pudonghot.ambition.crm.model.Customer;
import com.pudonghot.ambition.crm.common.Constants;
import com.pudonghot.ambition.crm.service.UserService;
import com.pudonghot.ambition.crm.mapper.CustomerMapper;
import com.pudonghot.ambition.crm.service.CustomerService;
import com.pudonghot.ambition.crm.model.CustomerPermission;
import org.springframework.beans.factory.annotation.Autowired;
import com.pudonghot.ambition.crm.service.CustomerIssueService;
import com.pudonghot.ambition.crm.model.CustomerYearToDateSale;
import com.pudonghot.ambition.crm.mapper.CustomerPermissionMapper;
import com.pudonghot.ambition.crm.form.create.CustomerFormForCreate;
import com.pudonghot.ambition.crm.form.update.CustomerFormForUpdate;
@ -66,7 +63,9 @@ public class CustomerServiceSupport
viewModel.setAttr("users", userService.listByCustomerId(id));
viewModel.setAttr("issues", customerIssueService.listViewModels(
new Search(CustomerYearToDateSale.CUSTOMER_ID, id)
.eq(CustomerYearToDateSale.ENABLED, true)));
.eq(CustomerYearToDateSale.ENABLED, true)
.desc(CustomerYearToDateSale.DATE_CREATED)
.desc(CustomerYearToDateSale.DATE_UPDATED)));
}
return viewModel;
}
@ -88,17 +87,39 @@ public class CustomerServiceSupport
protected void processViewModel(ViewModel<Customer> viewModel, Customer model) {
super.processViewModel(viewModel, model);
// List<Map<String, Object>> ytdSales;0wi
List<Map<String, Object>> ytdSales = null;
final String strYears = model.getYears();
final String strYtdSales = model.getYtdSales();
if (StringUtils.isNotBlank(strYears) &&
StringUtils.isNotBlank(strYtdSales)) {
String[] years = strYears.split("\\s*,\\s*");
String[] ytdSales = strYtdSales.split("\\s*,\\s*");
final String[] years = strYears.split("\\s*,\\s*");
final String[] sales = strYtdSales.split("\\s*,\\s*");
ytdSales = new ArrayList<>(years.length);
int i = 0;
for (final String year : years) {
final Map<String, Object> ytdSale = new HashMap<>();
ytdSale.put("year", year);
ytdSale.put("sale", Long.parseLong(sales[i++]));
ytdSales.add(ytdSale);
}
}
viewModel.setAttr("ytdSales", ytdSales != null ?
ytdSales : Collections.emptyList());
List<ViewModel<CustomerIssue>> recentIssues = customerIssueService.listViewModels(
new Search(CustomerYearToDateSale.CUSTOMER_ID, model.getId())
.eq(CustomerYearToDateSale.ENABLED, true)
.desc(CustomerYearToDateSale.DATE_CREATED)
.desc(CustomerYearToDateSale.DATE_UPDATED)
.limit(3));
if (!recentIssues.isEmpty()) {
int i = 0;
final Iterator<ViewModel<CustomerIssue>> it = recentIssues.iterator();
while (it.hasNext()) {
viewModel.setAttr("issue" + (++i), it.next());
}
}
// viewModel.setAttr("ytdSales", ytdSales);
}
/**

View File

@ -20,4 +20,4 @@ echo "Script Path [$prg_path]"
PROJECT_HOME=$(dirname $prg_path)
echo "Project Home [$PROJECT_HOME]"
cd "$PROJECT_HOME"
mvn clean package -pl crm -am -DskipTests -Ptest
mvn clean package -o -pl crm -am -DskipTests -Ptest

View File

@ -1,5 +1,7 @@
import Ember from 'ember';
export default Ember.Component.extend({
tagName: 'span'
tagName: 'span',
value: Ember.computed.alias('model'),
format: 'YYYY-MM-DD H:mm:ss'
});

View File

@ -3,6 +3,7 @@ import BaseListRoute from './../base-list';
const cols = ['showId',
'showName',
'showDateAdded',
'showYear',
'showYtdSale',
'showCountryCode',
@ -12,6 +13,9 @@ const cols = ['showId',
'showRegion',
'showSalesperson',
'showStatus',
'showIssue1',
'showIssue2',
'showIssue3',
];
const config = {
showAll: true,
@ -27,19 +31,24 @@ const config = {
colChanged: Ember.observer(...cols.concat(function() {
let me = this;
me.set('lock', true);
me.set('showAll',
cols.map(col => {
me.set('showAll', cols.map(col => {
return me[col];
}).reduce((val, prevVal) => {
return val && prevVal;
}, true));
me.set('lock', false);
me.set('countOfShowing', cols.filter(col => {
return me[col];
}).length);
}))
};
cols.forEach((col) => {
config[col] = !['showCountryCode', 'showState', 'showCity'].contains(col);
config[col] = !['showYear', 'showCountryCode', 'showState', 'showCity'].includes(col);
});
config.countOfShowing = cols.filter(col => {
return config[col];
}).length;
const TableOptions = Ember.Object.extend(config);
@ -50,9 +59,18 @@ export default BaseListRoute.extend({
}
},
breadcrumbs: [{text: 'Customers'}],
tableOptions: TableOptions.create(),
setupController(controller) {
let me = this;
me._super(...arguments);
controller.set('tableOptions', TableOptions.create());
controller.set('tableOptions', me.get('tableOptions'));
},
actions: {
expandYtdSales(row) {
Ember.set(row, 'expand', true);
},
collapseYtdSales(row) {
Ember.set(row, 'expand', false);
}
}
});

View File

@ -28,6 +28,7 @@ export default Ember.Route.extend({
statusList: parentController.get('model.statusList'),
criteria: criteria,
cols: [{col: 'name', name: 'Name'},
{col: 'dateAdded', name: 'Date Added'},
{col: 'year', name: 'Year'},
{col: 'ytdSale', name: 'YTD Sales'},
{col: 'countryCode', name: 'Country'},

View File

@ -1,3 +1,3 @@
{{#if model}}
{{moment-format model 'YYYY-MM-DD H:mm:ss'}}
{{#if value}}
{{moment-format value format}}
{{/if}}

View File

@ -35,11 +35,14 @@
{{#if tableOptions.showName}}
<th>Name</th>
{{/if}}
{{#if tableOptions.showDateAdded}}
<th>Added</th>
{{/if}}
{{#if tableOptions.showYear}}
<th>Years</th>
{{/if}}
{{#if tableOptions.showYtdSale}}
{{sortable-th name='sumYtdSales' text='Sum YTD Sales'}}
{{sortable-th name='sumYtdSales' text='Sales'}}
{{/if}}
{{#if tableOptions.showCountryCode}}
<th class="hidden-480">Country</th>
@ -62,6 +65,15 @@
{{#if tableOptions.showStatus}}
<th class="hidden-480">Status</th>
{{/if}}
{{#if tableOptions.showIssue1}}
<th class="hidden-480">Issue 1</th>
{{/if}}
{{#if tableOptions.showIssue2}}
<th class="hidden-480">Issue 2</th>
{{/if}}
{{#if tableOptions.showIssue3}}
<th class="hidden-480">Issue 3</th>
{{/if}}
<th>
<i class="ace-icon fa fa-cogs bigger-110 hidden-480"></i>
Settings
@ -84,6 +96,11 @@
{{it.name}}
</td>
{{/if}}
{{#if tableOptions.showDateAdded}}
<td>
{{date-cell value=it.dateAdded format='D/M/YYYY'}}
</td>
{{/if}}
{{#if tableOptions.showYear}}
<td>
{{it.years}}
@ -91,6 +108,19 @@
{{/if}}
{{#if tableOptions.showYtdSale}}
<td>
{{#if it.sumYtdSales}}
{{#if it.expand}}
<a style="cursor: pointer;" {{action (route-action 'collapseYtdSales' it)}}>
<span class="ui-icon ace-icon fa fa-minus center bigger-110 blue">
</span>
</a>
{{else}}
<a style="cursor: pointer;" {{action (route-action 'expandYtdSales' it)}}>
<span class="ui-icon ace-icon fa fa-plus center bigger-110 blue">
</span>
</a>
{{/if}}
{{/if}}
{{number-us it.sumYtdSales}}
</td>
{{/if}}
@ -129,6 +159,36 @@
{{it.statusText}}
</td>
{{/if}}
{{#if tableOptions.showIssue1}}
<td style="max-width: 32px">
{{#if it.issue1}}
{{it.issue1.issue}}
{{#link-to 'customer-issue.edit' it.issue1.id class="blue" title="Edit"}}
<i class="ace-icon fa fa-pencil bigger-60"></i>
{{/link-to}}
{{/if}}
</td>
{{/if}}
{{#if tableOptions.showIssue2}}
<td style="max-width: 32px">
{{#if it.issue2}}
{{it.issue2.issue}}
{{#link-to 'customer-issue.edit' it.issue2.id class="blue" title="Edit"}}
<i class="ace-icon fa fa-pencil bigger-60"></i>
{{/link-to}}
{{/if}}
</td>
{{/if}}
{{#if tableOptions.showIssue3}}
<td style="max-width: 32px">
{{#if it.issue3}}
{{it.issue3.issue}}
{{#link-to 'customer-issue.edit' it.issue3.id class="blue" title="Edit"}}
<i class="ace-icon fa fa-pencil bigger-60"></i>
{{/link-to}}
{{/if}}
</td>
{{/if}}
<td>
<div class="hidden-sm hidden-xs btn-group">
{{#link-to 'customer-issue.create' it.id class='btn btn-xs btn-success' title='创建注记'}}
@ -149,7 +209,7 @@
<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
<li>
{{#link-to 'customer-issue.create' it.id class='tooltip-info' data-rel='tooltip' title='创建注记'}}
{{#link-to 'customer-issue.create' it.id class='tooltip-info' data-rel='tooltip' title='Create Issue'}}
<span class="green">
<i class="ace-icon fa fa-tags bigger-120"></i>
</span>
@ -157,7 +217,7 @@
</li>
{{#if ajax.user.admin}}
<li>
{{#link-to 'customer.edit' it.id class='tooltip-info' data-rel='tooltip' title='编辑'}}
{{#link-to 'customer.edit' it.id class='tooltip-info' data-rel='tooltip' title='Edit'}}
<span class="blue">
<i class="ace-icon fa fa-pencil-square-o bigger-120"></i>
</span>
@ -169,6 +229,32 @@
</div>
</td>
</tr>
{{#if it.expand}}
<tr>
<td colspan="{{tableOptions.countOfShowing}}">
<table class="table table-striped table-hover dataTable table-bordered" style="border: 1px solid #ddd;">
<thead class="thin-border-bottom">
<tr>
<th>Year</th>
<th>Sale</th>
</tr>
</thead>
<tbody>
{{#each it.ytdSales as |yearSale|}}
<tr>
<td>
{{yearSale.year}}
</td>
<td>
{{number-us yearSale.sale}}
</td>
</tr>
{{/each}}
</tbody>
</table>
</td>
</tr>
{{/if}}
{{/each}}
</tbody>
</table>

View File

@ -14,7 +14,7 @@
<div class="control-group">
{{ace-checkbox label='ID' value=model.tableOptions.showId}}
{{ace-checkbox label='Name' value=model.tableOptions.showName}}
{{ace-checkbox label='Year' value=model.tableOptions.showYear}}
{{ace-checkbox label='Date Added' value=model.tableOptions.showDateAdded}}
{{ace-checkbox label='YTD Sales' value=model.tableOptions.showYtdSale}}
{{ace-checkbox label='Country' value=model.tableOptions.showCountryCode}}
{{ace-checkbox label='State' value=model.tableOptions.showState}}