Finished reports tree in the main page, including new report, save
report, new report directory and so on. TODO: save and load portlets information in reports.
This commit is contained in:
parent
61f90e503f
commit
a96d4341d1
|
@ -2,7 +2,7 @@ package haflow.dto.entity;
|
|||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
import org.hibernate.annotations.Cascade;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
|
@ -12,7 +12,6 @@ import javax.persistence.JoinColumn;
|
|||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
||||
@Entity
|
||||
@Table(name = "flow")
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
package haflow.dto.entity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table( name="portlet")
|
||||
public class Portlet {
|
||||
|
||||
private UUID id;
|
||||
private String title;
|
||||
private String type;
|
||||
private int position;
|
||||
|
||||
private Report report;
|
||||
|
||||
@Id
|
||||
@Column(name="id", length = 16)
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name="title")
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@Column(name="type")
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Column(name="position")
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="reportId",referencedColumnName="id")
|
||||
public Report getReport() {
|
||||
return report;
|
||||
}
|
||||
|
||||
public void setReport(Report report) {
|
||||
this.report = report;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
package haflow.dto.entity;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.persistence.CascadeType;
|
||||
import javax.persistence.Column;
|
||||
import javax.persistence.Entity;
|
||||
import javax.persistence.FetchType;
|
||||
import javax.persistence.Id;
|
||||
import javax.persistence.JoinColumn;
|
||||
import javax.persistence.ManyToOne;
|
||||
import javax.persistence.OneToMany;
|
||||
import javax.persistence.Table;
|
||||
|
||||
@Entity
|
||||
@Table( name="report")
|
||||
public class Report {
|
||||
|
||||
private UUID id;
|
||||
private String name;
|
||||
private Report parent;
|
||||
private boolean isDirectory;
|
||||
private Set<Portlet> portlets;
|
||||
private MainUser user;
|
||||
|
||||
@Id
|
||||
@Column(name = "id", length = 16)
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@Column(name = "name")
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="parentId", referencedColumnName="id")
|
||||
public Report getParent() {
|
||||
return parent;
|
||||
}
|
||||
public void setParent(Report parent) {
|
||||
this.parent = parent;
|
||||
}
|
||||
|
||||
@Column(name="isDirectory")
|
||||
public boolean isDirectory() {
|
||||
return isDirectory;
|
||||
}
|
||||
public void setDirectory(boolean isDirectory) {
|
||||
this.isDirectory = isDirectory;
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "report", cascade = CascadeType.ALL, orphanRemoval = true, fetch = FetchType.EAGER)
|
||||
public Set<Portlet> getPortlets() {
|
||||
return portlets;
|
||||
}
|
||||
public void setPortlets(Set<Portlet> portlets) {
|
||||
this.portlets = portlets;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="ownerId",referencedColumnName="id")
|
||||
public MainUser getUser() {
|
||||
return user;
|
||||
}
|
||||
public void setUser(MainUser user) {
|
||||
this.user = user;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,97 @@
|
|||
package haflow.service;
|
||||
|
||||
import haflow.dto.entity.MainUser;
|
||||
import haflow.dto.entity.Portlet;
|
||||
import haflow.dto.entity.Report;
|
||||
import haflow.util.SessionHelper;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.hibernate.Query;
|
||||
import org.hibernate.Session;
|
||||
import org.hibernate.Transaction;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ReportService {
|
||||
|
||||
private SessionHelper sessionHelper;
|
||||
|
||||
private SessionHelper getSessionHelper() {
|
||||
return sessionHelper;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
private void setSessionHelper(SessionHelper sessionHelper) {
|
||||
this.sessionHelper = sessionHelper;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public List<Report> getReportList(int userid){
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try{
|
||||
Query query = session.createQuery("select r from Report r where r.user.id =?");
|
||||
query.setInteger(0, userid);
|
||||
List<Report> reports = (List<Report>) query.list();
|
||||
for(Report report : reports){
|
||||
System.out.println(report.getId());
|
||||
}
|
||||
return reports;
|
||||
}catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return null;
|
||||
} finally {
|
||||
if (session != null)
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean saveReport(UUID reportId, String name, boolean isDirectory, UUID parentId, Set<Portlet> portlets,
|
||||
int userid) {
|
||||
Session session = this.getSessionHelper().openSession();
|
||||
Transaction transaction = session.beginTransaction();
|
||||
try {
|
||||
MainUser user = (MainUser) session.get(MainUser.class, userid);
|
||||
Report report = (Report) session.get(Report.class, reportId);
|
||||
Report parentReport = null;
|
||||
if(parentId != null)
|
||||
parentReport = (Report) session.get(Report.class, parentId);
|
||||
if (report == null) {
|
||||
report = new Report();
|
||||
report.setId(reportId);
|
||||
|
||||
report.setPortlets(new HashSet<Portlet>());
|
||||
report.setUser(user);
|
||||
}
|
||||
|
||||
report.setName(name);
|
||||
report.setDirectory(isDirectory);
|
||||
report.setParent(parentReport);
|
||||
report.getPortlets().clear();
|
||||
|
||||
for( Portlet portlet : portlets ){
|
||||
portlet.setReport(report);
|
||||
session.merge(portlet);
|
||||
report.getPortlets().add(portlet);
|
||||
}
|
||||
|
||||
session.merge(report);
|
||||
|
||||
transaction.commit();
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
transaction.rollback();
|
||||
return false;
|
||||
} finally {
|
||||
if (session != null)
|
||||
session.close();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package haflow.ui.controller;
|
||||
|
||||
import haflow.ui.helper.ReportHelper;
|
||||
import haflow.ui.model.ReportListModel;
|
||||
import haflow.ui.model.SaveReportModel;
|
||||
import haflow.ui.model.SaveReportResultModel;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMethod;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
@Controller
|
||||
@RequestMapping("/report")
|
||||
public class ReportController {
|
||||
|
||||
private ReportHelper reportHelper;
|
||||
|
||||
@Autowired
|
||||
private void setReportHelper(ReportHelper reportHelper) {
|
||||
this.reportHelper = reportHelper;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/{reportId}", method = RequestMethod.PUT)
|
||||
@ResponseBody
|
||||
public SaveReportResultModel put(@PathVariable UUID reportId,
|
||||
@RequestBody SaveReportModel model,HttpServletRequest request) {
|
||||
System.out.println("save report");
|
||||
return this.reportHelper.saveReport(reportId, model,(Integer)request.getSession().getAttribute("userid"));
|
||||
}
|
||||
|
||||
@RequestMapping(method = RequestMethod.GET)
|
||||
@ResponseBody
|
||||
public ReportListModel get(HttpServletRequest request) {
|
||||
int userid = (Integer)request.getSession().getAttribute("userid");
|
||||
ReportListModel reportListModel = this.reportHelper.getReportList(userid);
|
||||
if( reportListModel.getReports().size() == 0){
|
||||
SaveReportModel model = new SaveReportModel();
|
||||
model.setId(UUID.randomUUID());
|
||||
model.setIsdirectory(true);
|
||||
model.setName("Reports");
|
||||
model.setParentid(null);
|
||||
model.setPortlets(null);
|
||||
this.reportHelper.saveReport(model.getId(), model, userid);
|
||||
reportListModel = this.reportHelper.getReportList(userid);
|
||||
}
|
||||
return reportListModel;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,100 @@
|
|||
package haflow.ui.helper;
|
||||
|
||||
import haflow.dto.entity.Portlet;
|
||||
import haflow.dto.entity.Report;
|
||||
import haflow.service.ReportService;
|
||||
import haflow.ui.model.PortletModel;
|
||||
import haflow.ui.model.ReportListModel;
|
||||
import haflow.ui.model.SaveReportModel;
|
||||
import haflow.ui.model.SaveReportResultModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
@Component
|
||||
public class ReportHelper {
|
||||
|
||||
private ReportService reportService;
|
||||
|
||||
public ReportService getReportService() {
|
||||
return reportService;
|
||||
}
|
||||
|
||||
@Autowired
|
||||
public void setReportService(ReportService reportService) {
|
||||
this.reportService = reportService;
|
||||
}
|
||||
|
||||
public ReportListModel getReportList(int userid){
|
||||
List<Report> reports = this.reportService.getReportList(userid);
|
||||
ReportListModel reportListModel = new ReportListModel();
|
||||
List<SaveReportModel> reportModels = new ArrayList<SaveReportModel>();
|
||||
for( Report report : reports ){
|
||||
SaveReportModel reportModel = new SaveReportModel();
|
||||
reportModel.setId(report.getId());
|
||||
reportModel.setIsdirectory(report.isDirectory());
|
||||
reportModel.setName(report.getName());
|
||||
if( report.getParent() != null){
|
||||
reportModel.setParentid(report.getParent().getId());
|
||||
}else{
|
||||
reportModel.setParentid(null);
|
||||
}
|
||||
|
||||
Set<PortletModel> portletModels = new HashSet<PortletModel>();
|
||||
for(Portlet portlet : report.getPortlets()){
|
||||
PortletModel portletModel = new PortletModel();
|
||||
portletModel.setId(portlet.getId());
|
||||
portletModel.setPosition(portlet.getPosition());
|
||||
portletModel.setReportId(portlet.getReport().getId());
|
||||
portletModel.setTitle(portlet.getTitle());
|
||||
portletModel.setType(portlet.getType());
|
||||
}
|
||||
reportModel.setPortlets(portletModels);
|
||||
reportModels.add(reportModel);
|
||||
}
|
||||
reportListModel.setReports(reportModels);
|
||||
return reportListModel;
|
||||
}
|
||||
|
||||
public SaveReportResultModel saveReport(UUID reportId, SaveReportModel model,int userid) {
|
||||
boolean success = this.doSaveReport(reportId, model, userid);
|
||||
SaveReportResultModel result = new SaveReportResultModel();
|
||||
result.setFlowId(reportId);
|
||||
result.setSuccess(success);
|
||||
if (success) {
|
||||
result.setMessage("success");
|
||||
} else {
|
||||
result.setMessage("fail");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean doSaveReport(UUID reportId, SaveReportModel model,int userid) {
|
||||
Set<Portlet> portlets = new HashSet<Portlet>();
|
||||
if( model.getPortlets() != null){
|
||||
for( PortletModel portletModel : model.getPortlets()){
|
||||
if( !portletModel.getReportId().equals(reportId)){
|
||||
return false;
|
||||
}
|
||||
Portlet portlet = new Portlet();
|
||||
portlet.setId(portletModel.getId());
|
||||
portlet.setPosition(portletModel.getPosition());
|
||||
portlet.setTitle(portletModel.getTitle());
|
||||
portlet.setType(portletModel.getType());
|
||||
|
||||
portlets.add(portlet);
|
||||
}
|
||||
}
|
||||
boolean result = true;
|
||||
result = result
|
||||
&& this.getReportService().saveReport(reportId, model.getName(), model.getIsdirectory(), model.getParentid(), portlets, userid);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
package haflow.ui.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name="portlet")
|
||||
public class PortletModel {
|
||||
private UUID id;
|
||||
private String title;
|
||||
private String type;
|
||||
private int position;
|
||||
|
||||
private UUID reportId;
|
||||
|
||||
@XmlElement
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
public void setTitle(String title) {
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getType() {
|
||||
return type;
|
||||
}
|
||||
public void setType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public int getPosition() {
|
||||
return position;
|
||||
}
|
||||
public void setPosition(int position) {
|
||||
this.position = position;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public UUID getReportId() {
|
||||
return reportId;
|
||||
}
|
||||
public void setReportId(UUID reportId) {
|
||||
this.reportId = reportId;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,22 @@
|
|||
package haflow.ui.model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement( name = "reportListModel")
|
||||
public class ReportListModel {
|
||||
private List<SaveReportModel> reports;
|
||||
|
||||
@XmlElementWrapper(name = "reports")
|
||||
@XmlElement(name = "report")
|
||||
public List<SaveReportModel> getReports() {
|
||||
return reports;
|
||||
}
|
||||
|
||||
public void setReports(List<SaveReportModel> reports) {
|
||||
this.reports = reports;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,60 @@
|
|||
package haflow.ui.model;
|
||||
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
@XmlRootElement(name="saveReport")
|
||||
public class SaveReportModel {
|
||||
private UUID id;
|
||||
private String name;
|
||||
private boolean isdirectory;
|
||||
|
||||
private UUID parentid;
|
||||
private Set<PortletModel> portlets;
|
||||
|
||||
@XmlElement
|
||||
public UUID getId() {
|
||||
return id;
|
||||
}
|
||||
public void setId(UUID id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
public void setName(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public boolean getIsdirectory() {
|
||||
return isdirectory;
|
||||
}
|
||||
public void setIsdirectory(boolean isdirectory) {
|
||||
this.isdirectory = isdirectory;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public UUID getParentid() {
|
||||
return parentid;
|
||||
}
|
||||
public void setParentid(UUID parentid) {
|
||||
this.parentid = parentid;
|
||||
}
|
||||
|
||||
@XmlElementWrapper(name="portlets")
|
||||
@XmlElement( name="portlet")
|
||||
public Set<PortletModel> getPortlets() {
|
||||
return portlets;
|
||||
}
|
||||
|
||||
public void setPortlets(Set<PortletModel> portlets) {
|
||||
this.portlets = portlets;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
package haflow.ui.model;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import com.sun.xml.internal.txw2.annotation.XmlElement;
|
||||
|
||||
@XmlRootElement
|
||||
public class SaveReportResultModel {
|
||||
private boolean success;
|
||||
private UUID flowId;
|
||||
private String message;
|
||||
|
||||
@XmlElement
|
||||
public boolean isSuccess() {
|
||||
return success;
|
||||
}
|
||||
public void setSuccess(boolean success) {
|
||||
this.success = success;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public UUID getFlowId() {
|
||||
return flowId;
|
||||
}
|
||||
public void setFlowId(UUID flowId) {
|
||||
this.flowId = flowId;
|
||||
}
|
||||
|
||||
@XmlElement
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,9 @@
|
|||
<mapping class="haflow.dto.entity.MainUser"/>
|
||||
<mapping class="haflow.dto.entity.FlowRunHistory" />
|
||||
|
||||
<mapping class="haflow.dto.entity.Report" />
|
||||
<mapping class="haflow.dto.entity.Portlet" />
|
||||
|
||||
<mapping class="haflow.dto.profile.NodeAppearance" />
|
||||
<mapping class="haflow.dto.profile.NodeConfiguration" />
|
||||
</session-factory>
|
||||
|
|
|
@ -43,8 +43,8 @@
|
|||
<script type="text/javascript" src="<%=basePath%>/script/haflow.flow_operation.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.flow_operation_helper.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.hdfs.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.report.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.report_list.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.report.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.jsplumb.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.oozie_hive.js"></script>
|
||||
<script type="text/javascript" src="<%=basePath%>/script/haflow.toolbar.js"></script>
|
||||
|
|
|
@ -6,30 +6,41 @@ dojo.require("dojox.charting.axis2d.Default");
|
|||
dojo.require("dojox.charting.plot2d.Columns");
|
||||
dojo.require("dojo/fx/easing");
|
||||
|
||||
HAFlow.Main.prototype.openReport = function(reportId){
|
||||
this.loadReport(reportId);
|
||||
};
|
||||
//HAFlow.Main.prototype.openReport = function(reportId){
|
||||
// this.loadReport(reportId);
|
||||
//};
|
||||
|
||||
HAFlow.Main.prototype.newReport = function(parentId) {
|
||||
var newReportId = HAFlow.generateUUID();
|
||||
this.newReportItem(newReportId, parentId, false);
|
||||
this.openReport(newReportId);
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.newReportDirectory = function(parentId) {
|
||||
var newReportId = HAFlow.generateUUID();
|
||||
this.newReportItem(newReportId, parentId, true);
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.newReportItem = function(newReportId, parentId, isdirectory){
|
||||
this.reports[newReportId] = {};
|
||||
this.reports[newReportId].id = newReportId;
|
||||
this.reports[newReportId].name = "NewReport";
|
||||
this.reports[newReportId].name = "NewReport" + (isdirectory ? "Dir" : "");
|
||||
this.reports[newReportId].isdirectory = isdirectory;
|
||||
this.reports[newReportId].parentid = parentId;
|
||||
this.reports[newReportId].portlets = new Array();
|
||||
|
||||
this.loadReport(newReportId);
|
||||
this.saveReport(newReportId);//save this.reports[newReportId]
|
||||
|
||||
this.reportListStore.put({
|
||||
id : newReportId,
|
||||
name : this.reports[newReportId].name,
|
||||
directory : false,
|
||||
isdirectory : isdirectory,
|
||||
parent : parentId
|
||||
});
|
||||
|
||||
this.saveReport(newReportId);//save this.reports[newReportId]
|
||||
};
|
||||
|
||||
//private
|
||||
HAFlow.Main.prototype.loadReport = function(reportId){
|
||||
HAFlow.Main.prototype.openReport = function(reportId){
|
||||
var contentPane = dijit.byId("reportContainerPane_" + reportId);//mush be dijit.byId
|
||||
if( contentPane == null){
|
||||
var currentReport = this.reports[reportId];
|
||||
|
@ -51,9 +62,22 @@ HAFlow.Main.prototype.loadReport = function(reportId){
|
|||
};
|
||||
|
||||
|
||||
|
||||
HAFlow.Main.prototype.saveReport = function(reportId){
|
||||
|
||||
var _currentInstance = this;
|
||||
$.ajax({
|
||||
url : _currentInstance.basePath + "report/" + reportId,
|
||||
type : "PUT",
|
||||
dataType : "json",
|
||||
contentType : "application/json",
|
||||
data : JSON.stringify(_currentInstance.reports[reportId]),//reports???
|
||||
success : function(data, status) {
|
||||
HAFlow.showDialog("Save Report", "Report saved.");
|
||||
},
|
||||
error : function(request, status, error) {
|
||||
HAFlow.showDialog("Error", "An error occurred while saving flow: "
|
||||
+ error + " status : " + status);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
// public
|
||||
|
@ -154,20 +178,24 @@ HAFlow.Main.prototype.onReportModuleAdded = function(currentInstance, reportId,
|
|||
var newPortletId = HAFlow.generateUUID();
|
||||
if (reportModuleId == "text") {
|
||||
var currentPortlet = {
|
||||
id: newPortletId,
|
||||
title: reportModuleId,
|
||||
report_id: reportId,
|
||||
index: 1,
|
||||
type: "text"};
|
||||
id: newPortletId,
|
||||
title: reportModuleId,
|
||||
type: "text",
|
||||
position: 1,
|
||||
|
||||
reportId: reportId,
|
||||
};
|
||||
this.reports[reportId].portlets.push(currentPortlet);
|
||||
this.addReport(reportId, currentPortlet);
|
||||
} else if (reportModuleId == "curve") {
|
||||
var currentPortlet = {
|
||||
id: newPortletId,
|
||||
title: reportModuleId,
|
||||
report_id: reportId,
|
||||
index: 1,
|
||||
type: "curve"};
|
||||
type: "curve",
|
||||
position: 1,
|
||||
|
||||
reportId: reportId,
|
||||
};
|
||||
this.reports[reportId].portlets.push(currentPortlet);
|
||||
this.addReport(reportId, currentPortlet);
|
||||
} else {
|
||||
|
|
|
@ -5,19 +5,29 @@ HAFlow.Main.prototype.initReportList = function() {
|
|||
title: "Reports"
|
||||
});
|
||||
this.ui.leadingContainer.addChild(reportListContentPane);
|
||||
this.initReportListStore();
|
||||
this.getReportList();
|
||||
this.initReportListTree();
|
||||
|
||||
var _currentInstance = this;
|
||||
$.ajax({
|
||||
url: this.basePath + "report",
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
data: {},
|
||||
success: function(data, status) {
|
||||
_currentInstance.initReportListStore();
|
||||
_currentInstance.fillReportListStore(data);
|
||||
_currentInstance.fillReportsData(data);
|
||||
_currentInstance.initReportListTree();
|
||||
},
|
||||
error: function(request, status, error) {
|
||||
HAFlow.showDialog("Error", "An error occurred while loading flow list: " + error);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
//private
|
||||
HAFlow.Main.prototype.initReportListStore = function() {
|
||||
this.reportListStore = new dojo.store.Observable(new dojo.store.Memory({
|
||||
data: [{
|
||||
id: "reports",
|
||||
name: "Reports",
|
||||
directory: true,
|
||||
parent: null
|
||||
}],
|
||||
data: [],
|
||||
getChildren: function(object) {
|
||||
return this.query({
|
||||
parent: object.id
|
||||
|
@ -26,53 +36,70 @@ HAFlow.Main.prototype.initReportListStore = function() {
|
|||
}));
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.getReportList = function(path) {
|
||||
var _currentInstance = this;
|
||||
// $.ajax({
|
||||
// url: this.basePath + "report/list",
|
||||
// type: "GET",
|
||||
// dataType: "json",
|
||||
// data: {
|
||||
// path: path
|
||||
// },
|
||||
// success: function(data, status) {
|
||||
// _currentInstance.refreshHdfsFileList(data);
|
||||
// },
|
||||
// error: function(request, status, error) {
|
||||
// HAFlow.showDialog("Error", "An error occurred while loading flow list: " + error);
|
||||
// }
|
||||
// });
|
||||
var data = [];
|
||||
data.reports = [{id: '1', name: 'root', parent: 'reports', directory: true},
|
||||
{id: '1223', name: '1223', parent: '1', directory: true},
|
||||
{id: '1224', name: '1224', parent: '1', directory: false}];
|
||||
_currentInstance.refreshReportList(data);
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.refreshReportList = function(data) {
|
||||
var _currentInstance = this;
|
||||
HAFlow.Main.prototype.fillReportListStore = function(data) {
|
||||
for (var i = 0; i < data.reports.length; i++) {
|
||||
var dataItem = data.reports[i];
|
||||
this.reportListStore.put({
|
||||
id: dataItem.id,
|
||||
name: dataItem.name,
|
||||
isDirectory: dataItem.directory,
|
||||
parent: dataItem.parent,
|
||||
isdirectory: dataItem.isdirectory,
|
||||
parent: dataItem.parentid,
|
||||
});
|
||||
// if (data.files[i].directory) {
|
||||
// instance.getHdfsFileList(parentPath + "/" + data.files[i].name);
|
||||
// }
|
||||
}
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.fillReportsData = function(data) {
|
||||
for (var i = 0; i < data.reports.length; i++) {
|
||||
var reportItem = data.reports[i];
|
||||
var reportItemId = reportItem.id;
|
||||
this.reports[reportItemId] = {};
|
||||
this.reports[reportItemId].id = reportItemId;
|
||||
this.reports[reportItemId].name = reportItem.name;
|
||||
this.reports[reportItemId].isdirectory = reportItem.isdirectory;
|
||||
this.reports[reportItemId].parentid = reportItem.parentid;
|
||||
this.reports[reportItemId].portlets = new Array();//TODO
|
||||
}
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.checkReportItem = function(isDirectory, needsDirectory){
|
||||
// if( tn.isdirectory ){
|
||||
// _currentInstance.newReport(tn.item.id);
|
||||
// }else{
|
||||
// HAFlow.showDialog("Error", "It's not a flow directory! ");
|
||||
// }
|
||||
|
||||
if( needsDirectory ){
|
||||
if( isDirectory){
|
||||
return true;
|
||||
}else{
|
||||
HAFlow.showDialog("Error", "It's not a flow directory! ");
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
if( isDirectory){
|
||||
HAFlow.showDialog("Error", "It's not a flow! ");
|
||||
return false;
|
||||
}else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
HAFlow.Main.prototype.initReportListTree = function() {
|
||||
var rootId;
|
||||
for(var i = 0; i < this.reportListStore.data.length; i++ ){
|
||||
if( this.reportListStore.data[i].parent == null){
|
||||
rootId = this.reportListStore.data[i].id;
|
||||
break;
|
||||
}
|
||||
}
|
||||
var treeModel = new dijit.tree.ObjectStoreModel({
|
||||
store: this.reportListStore,
|
||||
query: {
|
||||
id: "reports"
|
||||
id: rootId,
|
||||
},
|
||||
mayHaveChildren: function(item) {
|
||||
return item.isDirectory;
|
||||
return item.isdirectory;
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -108,21 +135,33 @@ HAFlow.Main.prototype.initReportListTree = function() {
|
|||
id: "renameReportMenuItem",
|
||||
label: "Rename"
|
||||
});
|
||||
this.menu.reportTreeMenu.saveReportMenuItem = new dijit.MenuItem({
|
||||
id: "saveReportMenuItem",
|
||||
label: "Save"
|
||||
});
|
||||
|
||||
this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.newReportMenuItem);
|
||||
this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.newReportDirectoryMenuItem);
|
||||
this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.deleteReportMenuItem);
|
||||
this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.renameReportMenuItem);
|
||||
this.menu.reportTreeMenu.addChild(this.menu.reportTreeMenu.saveReportMenuItem);
|
||||
|
||||
dojo.connect(this.menu.reportTreeMenu.newReportMenuItem, "onClick",
|
||||
function() {
|
||||
var tn = dijit.byNode(this.getParent().currentTarget);
|
||||
var tn = dijit.byNode(this.getParent().currentTarget);
|
||||
var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, true);
|
||||
if( checkResult ){
|
||||
_currentInstance.newReport(tn.item.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
dojo.connect(this.menu.reportTreeMenu.newReportDirectoryMenuItem, "onClick",
|
||||
function() {
|
||||
|
||||
});
|
||||
var tn = dijit.byNode(this.getParent().currentTarget);
|
||||
var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, true);
|
||||
if( checkResult ){
|
||||
_currentInstance.newReportDirectory(tn.item.id);
|
||||
}
|
||||
});
|
||||
dojo.connect(this.menu.reportTreeMenu.deleteReportMenuItem, "onClick",
|
||||
function() {
|
||||
|
||||
|
@ -131,25 +170,29 @@ HAFlow.Main.prototype.initReportListTree = function() {
|
|||
function() {
|
||||
|
||||
});
|
||||
dojo.connect(this.menu.reportTreeMenu.saveReportMenuItem, "onClick",
|
||||
function() {
|
||||
var tn = dijit.byNode(this.getParent().currentTarget);
|
||||
var checkResult = _currentInstance.checkReportItem(tn.item.isdirectory, false);
|
||||
if( checkResult ){
|
||||
_currentInstance.saveReport(tn.item.id);
|
||||
}
|
||||
});
|
||||
|
||||
this.menu.reportTreeMenu.startup();
|
||||
tree.on("click",
|
||||
function(item) {
|
||||
if (item.directory != "true") {
|
||||
var information = [];
|
||||
information.id = item.id;
|
||||
information.name = item.name;
|
||||
_currentInstance.onReportClicked(_currentInstance, information);
|
||||
}
|
||||
},
|
||||
true);
|
||||
tree.on("click", function(item) {
|
||||
var information = [];
|
||||
information.id = item.id;
|
||||
information.name = item.name;
|
||||
_currentInstance.onReportClicked(_currentInstance, information);
|
||||
}, true);
|
||||
var picture = new RegExp("^[A-Za-z0-9_]*\.jpg$");
|
||||
var text = new RegExp("^[A-Za-z0-9_]*\.(txt|ini)$");
|
||||
var csv = new RegExp("^[A-Za-z0-9_-]*\.csv$");
|
||||
|
||||
tree.on("dblclick",
|
||||
function(reportItem) {
|
||||
if (reportItem.isDirectory != true) {
|
||||
if (!reportItem.isdirectory) {
|
||||
_currentInstance.openReport(reportItem.id);
|
||||
}
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue