提交 9f69ba2b 编写于 作者: A ainilife

New feature : suspend or resume an abtest

上级 d25b9443
......@@ -9,6 +9,7 @@ import javax.servlet.ServletException;
import org.unidal.dal.jdbc.DalException;
import org.unidal.lookup.annotation.Inject;
import org.unidal.web.mvc.ErrorObject;
import org.unidal.web.mvc.PageHandler;
import org.unidal.web.mvc.annotation.InboundActionMeta;
import org.unidal.web.mvc.annotation.OutboundActionMeta;
......@@ -34,7 +35,55 @@ public class Handler implements PageHandler<Context> {
@PayloadMeta(Payload.class)
@InboundActionMeta(name = "abtest")
public void handleInbound(Context ctx) throws ServletException, IOException {
// TODO
Payload payload = ctx.getPayload();
Action action = payload.getAction();
if (action == Action.LIST) {
handleStatusChangeActions(ctx);
}
}
private void handleStatusChangeActions(Context ctx) {
Payload payload = ctx.getPayload();
ErrorObject error = new ErrorObject("disable");
String[] ids = payload.getIds();
if (ids != null && ids.length != 0) {
for (String id : ids) {
System.out.println("change status for " + id);
try {
int intID = Integer.parseInt(id);
Abtest abtest = m_abtestDao.findByPK(intID, AbtestEntity.READSET_FULL);
if (payload.getDisableAbtest() == -1) { // suspend
if (!abtest.isDisabled()) {
abtest.setDisabled(true);
m_abtestDao.updateByPK(abtest, AbtestEntity.UPDATESET_DISABLE);
} else {
error.addArgument(id, "Abtest " + id + " has been already suspended!");
}
} else if (payload.getDisableAbtest() == 1) { // resume
if (abtest.isDisabled()) {
abtest.setDisabled(false);
m_abtestDao.updateByPK(abtest, AbtestEntity.UPDATESET_DISABLE);
} else {
error.addArgument(id, "Abtest " + id + " has been already active!");
}
}
} catch (NumberFormatException e) {
// do nothing
} catch (DalException e) {
}
}
if (error.getArguments().isEmpty()) {
ErrorObject success = new ErrorObject("success");
ctx.addError(success);
} else {
ctx.addError(error);
}
}
}
@Override
......@@ -122,10 +171,10 @@ public class Handler implements PageHandler<Context> {
int fromIndex = (payload.getPageNum() - 1) * m_pageSize;
int toIndex = (fromIndex + m_pageSize) <= totalSize ? (fromIndex + m_pageSize) : totalSize;
for(int i = fromIndex ; i < toIndex ; i++){
for (int i = fromIndex; i < toIndex; i++) {
reports.add(new ABTestReport(entities.get(i), now));
}
model.setTotalPages(totalPages);
model.setDate(now);
model.setReports(reports);
......
......@@ -18,8 +18,8 @@ public class Payload implements ActionPayload<SystemPage, Action> {
@FieldMeta("pageNum")
private int m_pageNum;
@FieldMeta("enable")
private boolean m_enableAbtest;
@FieldMeta("suspend")
private int m_disableAbtest;
@FieldMeta("ids")
private String m_ids;
......@@ -75,16 +75,21 @@ public class Payload implements ActionPayload<SystemPage, Action> {
m_page = SystemPage.getByName(page, SystemPage.ABTEST);
}
public boolean isEnableAbtest() {
return m_enableAbtest;
}
public int getDisableAbtest() {
return m_disableAbtest;
}
public void setEnableAbtest(boolean enableAbtest) {
m_enableAbtest = enableAbtest;
}
public void setDisableAbtest(int disableAbtest) {
m_disableAbtest = disableAbtest;
}
public String getIds() {
return m_ids;
public String[] getIds() {
if (m_ids != null) {
String[] ids = m_ids.split("-");
return ids;
} else {
return null;
}
}
public void setIds(String ids) {
......@@ -99,5 +104,9 @@ public class Payload implements ActionPayload<SystemPage, Action> {
if (m_status == null) {
m_status = "all";
}
if (m_disableAbtest != -1 && m_disableAbtest != 1) {
m_disableAbtest = 0;
}
}
}
......@@ -3,7 +3,13 @@
<entity name="abtest" table="abtest" alias="a">
<member name="creation-date" insert-expr="NOW()" />
<member name="modify-date" insert-expr="NOW()" update-expr="NOW()" />
<member name="disabled" field="isDisabled" value-type="boolean" length="3" nullable="false" />
<member name="disabled" field="disabled" value-type="boolean" length="3" nullable="false" />
<updatesets>
<updateset name="DISABLE">
<member name="disabled" />
<member name="modify-date" />
</updateset>
</updatesets>
<query-defs>
<query name="find-all-abtest" type="SELECT" multiple="true">
<statement><![CDATA[
......
......@@ -7,7 +7,36 @@ $(document).ready(function() {
}
});
$("#prevNavigation").click(function(){
//$(".pager .disabled").not("#prevNavigation").not("nextNavigation").next()
$("#btnSuspend").click(function(){
var checkbox = $(".table input[type='checkbox']:checked");
var id = "";
for(var i = 0 ; i < checkbox.length ; i++){
id = id + $(":nth-child(2)",$(checkbox[i]).closest('tr')).html() + "-";
}
url = window.location.href;
index = url.indexOf("&suspend");
if(index != -1){
window.location.href = url.substring(0,index) + "&suspend=-1&ids=" + id;
}else{
window.location.href = url + "&suspend=-1&ids=" + id;
}
loaction.reload();
});
$("#btnResume").click(function(){
var checkbox = $(".table input[type='checkbox']:checked");
var id = "";
for(var i = 0 ; i < checkbox.length ; i++){
id = id + $(":nth-child(2)",$(checkbox[i]).closest('tr')).html() + "-";
}
url = window.location.href;
index = url.indexOf("&suspend");
if(index != -1){
window.location.href = url.substring(0,index) + "&suspend=1&ids=" + id;
}else{
window.location.href = url + "&suspend=1&ids=" + id;
}
loaction.reload();
});
});
\ No newline at end of file
......@@ -122,6 +122,24 @@
</div>
</div>
<div class="span10 column">
<c:if test="${not empty ctx.errors}">
<c:forEach var="item" items="${ctx.errors}">
<c:if test="${item.code eq 'disable' }">
<div id="alertDiv" class="alert alert-error" style=" margin-bottom: 10px">
<button type="button" class="close" data-dismiss="alert">&times;</button>
<c:forEach var="argument" items="${item.arguments}">
<strong>Error!</strong> <c:out value="${argument.value}"/><br>
</c:forEach>
</div>
</c:if>
<c:if test="${item.code eq 'success' }">
<div id="alertDiv" class="alert" style=" margin-bottom: 10px">
<button type="button" class="close" data-dismiss="alert alert-success">&times;</button>
<strong>Success!</strong>
</div>
</c:if>
</c:forEach>
</c:if>
<div style="margin-bottom: 10px;">
<button class="btn" type="button">
<label class="checkbox"> <input id="ckall" type="checkbox"></input></label>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册