How to use uploadFile method in Webdriverio

Best JavaScript code snippet using webdriverio-monorepo

Run Webdriverio automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

reportlogic.js

Source: reportlogic.js Github

copy
1const OperatorModel  = require( '../models/operatormodel')
2const { Sequelize, Model, DataTypes } = require('sequelize');
3const { Op, QueryTypes } = require("sequelize");
4
5
6class ReportLogic {
7    static async getAllPostersWithPackageItems(sequelize)
8    {
9        try{
10            const posters = await sequelize.query("select * from uploadfile u inner join filepackageitem i " +
11            "on i.upload_file_id = u.id", { type: QueryTypes.SELECT });
12
13            return { success: true, payload: posters};
14        }
15        catch(err)
16        {
17            return {success: false, error: err, message: err.message}
18        }
19    }
20
21    static async getAllPosters(sequelize, offset, limit)
22    {
23        try{
24
25            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'poster'";
26
27            let sql = "select uploadfile.id, uploadfile.filename, " +
28            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.upload_date, " +
29            "count(filepackageitem.upload_file_id) as total from " +
30            "uploadfile left join " +
31            "filepackageitem on " +
32            "uploadfile.id = filepackageitem.upload_file_id " +
33            "where \"uploadfile\".\"imageCategory\" like 'poster' " +
34            "group by uploadfile.id, uploadfile.filename, " +
35            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.upload_date " +
36            "order by uploadfile.id desc " +
37            "offset " + offset + " limit " + limit;
38
39            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
40            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
41
42            return { success: true, payload: posters, allTotal: totalData};
43        }
44        catch(err)
45        {
46            return {success: false, error: err, message: err.message}
47        }
48    }
49
50    static async getAllPostersByUploader(sequelize, uploader, offset, limit, opt=null)
51    {
52        try{
53
54            let sqlwhere = "";
55            if(opt != null)
56            {
57                if(opt.outlet != "*")
58                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
59
60                if(opt.date != "*")
61                {
62                    let dt = new Date(opt.date).toISOString().slice(0, 10)
63                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
64                }
65                   
66            }
67
68            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'poster' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere;
69
70            let sql = "select uploadfile.id, uploadfile.filename, " +
71            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
72            "count(filepackageitem.upload_file_id) as total from " +
73            "uploadfile left join " +
74            "filepackageitem on " +
75            "uploadfile.id = filepackageitem.upload_file_id " +
76            "where \"uploadfile\".\"imageCategory\" like 'poster' " +
77            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
78            "group by uploadfile.id, uploadfile.filename, " +
79            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
80            "order by uploadfile.id desc " +
81            "offset " + offset + " limit " + limit;
82
83            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
84            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
85
86            return { success: true, payload: posters, allTotal: totalData};
87        }
88        catch(err)
89        {
90            return {success: false, error: err, message: err.message}
91        }
92    }
93
94
95    static async getAllStoreFrontsWithPackageItems(sequelize)
96    {
97        try{
98            const posters = await sequelize.query("select * from uploadfile u inner join storefrontitem i " +
99            "on i.upload_file_id = u.id", { type: QueryTypes.SELECT });
100
101            return { success: true, payload: posters};
102        }
103        catch(err)
104        {
105            return {success: false, error: err, message: err.message}
106        }
107    }
108
109    static async getAllStoreFronts(sequelize, offset, limit)
110    {
111        try{
112
113            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'storefront'";
114
115            let sql = "select uploadfile.id, uploadfile.filename, " +
116            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
117            "count(storefrontitem.upload_file_id) as total from " +
118            "uploadfile left join " +
119            "storefrontitem on " +
120            "uploadfile.id = storefrontitem.upload_file_id " +
121            "where \"uploadfile\".\"imageCategory\" like 'storefront' " +
122            "group by uploadfile.id, uploadfile.filename, " +
123            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
124            "order by uploadfile.id desc " +
125            "offset " + offset + " limit " + limit;
126
127            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
128            const storefronts = await sequelize.query(sql, { type: QueryTypes.SELECT });
129
130            return { success: true, payload: storefronts, allTotal: totalData};
131        }
132        catch(err)
133        {
134            return {success: false, error: err, message: err.message}
135        }
136    }
137
138    static async getAllStoreFrontsByUploader(sequelize, uploader, offset, limit, opt=null)
139    {
140        try{
141            let sqlwhere = "";
142            if(opt != null)
143            {
144                if(opt.outlet != "*")
145                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
146
147                if(opt.date != "*")
148                {
149                    let dt = new Date(opt.date).toISOString().slice(0, 10)
150                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
151                }
152                   
153            }
154
155            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'storefront' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' "  + sqlwhere;
156
157            let sql = "select uploadfile.id, uploadfile.filename, " +
158            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
159            "count(storefrontitem.upload_file_id) as total from " +
160            "uploadfile left join " +
161            "storefrontitem on " +
162            "uploadfile.id = storefrontitem.upload_file_id " +
163            "where \"uploadfile\".\"imageCategory\" like 'storefront' " +
164            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
165            "group by uploadfile.id, uploadfile.filename, " +
166            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
167            "order by uploadfile.id desc " +
168            "offset " + offset + " limit " + limit;
169
170            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
171            const storefronts = await sequelize.query(sql, { type: QueryTypes.SELECT });
172
173            return { success: true, payload: storefronts, allTotal: totalData};
174        }
175        catch(err)
176        {
177            return {success: false, error: err, message: err.message}
178        }
179    }
180}
181
182module.exports = ReportLogic;
Full Screen

zyFile.js

Source: zyFile.js Github

copy
1/*
2 * zyFile.js 基于HTML5 文件上传的核心脚本
3*/
4var ZYFILE = {
5		fileInput : null,             // 选择文件按钮dom对象
6		uploadInput : null,           // 上传文件按钮dom对象
7		dragDrop: null,				  //拖拽敏感区域
8		url : "",  					  // 上传action路径
9		uploadFile : [],  			  // 需要上传的文件数组
10		lastUploadFile : [],          // 上一次选择的文件数组,方便继续上传使用
11		perUploadFile : [],           // 存放永久的文件数组,方便删除使用
12		fileNum : 0,                  // 代表文件总个数,因为涉及到继续添加,所以下一次添加需要在它的基础上添加索引
13		/* 提供给外部的接口 */
14		filterFile : function(files){ // 提供给外部的过滤文件格式等的接口,外部需要把过滤后的文件返回
15			return files;
16		},
17		onSelect : function(selectFile, files){      // 提供给外部获取选中的文件,供外部实现预览等功能  selectFile:当前选中的文件  allFiles:还没上传的全部文件
18			
19		},
20		onDelete : function(file, files){            // 提供给外部获取删除的单个文件,供外部实现删除效果  file:当前删除的文件  files:删除之后的文件
21			
22		},
23		onProgress : function(file, loaded, total){  // 提供给外部获取单个文件的上传进度,供外部实现上传进度效果
24			
25		},
26		onSuccess : function(file, responseInfo){    // 提供给外部获取单个文件上传成功,供外部实现成功效果
27			
28		},
29		onFailure : function(file, responseInfo){    // 提供给外部获取单个文件上传失败,供外部实现失败效果
30		
31		},
32		onComplete : function(responseInfo){         // 提供给外部获取全部文件上传完成,供外部实现完成效果
33			
34		},
35		
36		/* 内部实现功能方法 */
37		// 获得选中的文件
38		//文件拖放
39		funDragHover: function(e) {
40			e.stopPropagation();
41			e.preventDefault();
42			this[e.type === "dragover"? "onDragOver": "onDragLeave"].call(e.target);
43			return this;
44		},
45		// 获取文件
46		funGetFiles : function(e){  
47			var self = this;
48			// 取消鼠标经过样式
49			this.funDragHover(e);
50			// 从事件中获取选中的所有文件
51			var files = e.target.files || e.dataTransfer.files;
52			self.lastUploadFile = this.uploadFile;
53			this.uploadFile = this.uploadFile.concat(this.filterFile(files));
54			var tmpFiles = [];
55			
56			// 因为jquery的inArray方法无法对object数组进行判断是否存在于,所以只能提取名称进行判断
57			var lArr = [];  // 之前文件的名称数组
58			var uArr = [];  // 现在文件的名称数组
59			$.each(self.lastUploadFile, function(k, v){
60				lArr.push(v.name);
61			});
62			$.each(self.uploadFile, function(k, v){
63				uArr.push(v.name);
64			});
65			
66			$.each(uArr, function(k, v){
67				// 获得当前选择的每一个文件   判断当前这一个文件是否存在于之前的文件当中
68				if($.inArray(v, lArr) < 0){  // 不存在
69					tmpFiles.push(self.uploadFile[k]);
70				}
71			});
72			
73			// 如果tmpFiles进行过过滤上一次选择的文件的操作,需要把过滤后的文件赋值
74			//if(tmpFiles.length!=0){
75				this.uploadFile = tmpFiles;
76			//}
77			
78			// 调用对文件处理的方法
79			this.funDealtFiles();
80			
81			return true;
82		},
83		// 处理过滤后的文件,给每个文件设置下标
84		funDealtFiles : function(){
85			var self = this;
86			// 目前是遍历所有的文件,给每个文件增加唯一索引值
87			$.each(this.uploadFile, function(k, v){
88				// 因为涉及到继续添加,所以下一次添加需要在总个数的基础上添加
89				v.index = self.fileNum;
90				// 添加一个之后自增
91				self.fileNum++;
92			});
93			// 先把当前选中的文件保存备份
94			var selectFile = this.uploadFile;  
95			// 要把全部的文件都保存下来,因为删除所使用的下标是全局的变量
96			this.perUploadFile = this.perUploadFile.concat(this.uploadFile);
97			// 合并下上传的文件
98			this.uploadFile = this.lastUploadFile.concat(this.uploadFile);
99			
100			// 执行选择回调
101			this.onSelect(selectFile, this.uploadFile);
102			console.info("继续选择");
103			console.info(this.uploadFile);
104			return this;
105		},
106		// 处理需要删除的文件  isCb代表是否回调onDelete方法  
107		// 因为上传完成并不希望在页面上删除div,但是单独点击删除的时候需要删除div   所以用isCb做判断
108		funDeleteFile : function(delFileIndex, isCb){
109			var self = this;  // 在each中this指向没个v  所以先将this保留
110			
111			var tmpFile = [];  // 用来替换的文件数组
112			// 合并下上传的文件
113			var delFile = this.perUploadFile[delFileIndex];
114			console.info(delFile);
115			// 目前是遍历所有的文件,对比每个文件  删除
116			$.each(this.uploadFile, function(k, v){
117				if(delFile != v){
118					// 如果不是删除的那个文件 就放到临时数组中
119					tmpFile.push(v);
120				}else{
121					
122				}
123			});
124			this.uploadFile = tmpFile;
125			if(isCb){  // 执行回调
126				// 回调删除方法,供外部进行删除效果的实现
127				self.onDelete(delFile, this.uploadFile);
128			}
129			
130			console.info("还剩这些文件没有上传:");
131			console.info(this.uploadFile);
132			return true;
133		},
134		// 上传多个文件
135		funUploadFiles : function(){
136			var self = this;  // 在each中this指向没个v  所以先将this保留
137			// 遍历所有文件  ,在调用单个文件上传的方法
138			$.each(this.uploadFile, function(k, v){
139				self.funUploadFile(v);
140			});
141		},
142		// 上传单个个文件
143		funUploadFile : function(file){
144			var self = this;  // 在each中this指向没个v  所以先将this保留
145			
146			var formdata = new FormData();
147			formdata.append("fileList", file);	         		
148			var xhr = new XMLHttpRequest();
149			// 绑定上传事件
150			// 进度
151		    xhr.upload.addEventListener("progress",	 function(e){
152		    	// 回调到外部
153		    	self.onProgress(file, e.loaded, e.total);
154		    }, false); 
155		    // 完成
156		    xhr.addEventListener("load", function(e){
157	    		// 从文件中删除上传成功的文件  false是不执行onDelete回调方法
158		    	self.funDeleteFile(file.index, false);
159		    	// 回调到外部
160		    	self.onSuccess(file, xhr.responseText);
161		    	if(self.uploadFile.length==0){
162		    		// 回调全部完成方法
163		    		self.onComplete("全部完成");
164		    	}
165		    }, false);  
166		    // 错误
167		    xhr.addEventListener("error", function(e){
168		    	// 回调到外部
169		    	self.onFailure(file, xhr.responseText);
170		    }, false);  
171			
172			xhr.open("POST",self.url, true);
173			xhr.setRequestHeader("X_FILENAME", file.name);
174			xhr.send(formdata);
175		},
176		// 返回需要上传的文件
177		funReturnNeedFiles : function(){
178			return this.uploadFile;
179		},
180		
181		// 初始化
182		init : function(){  // 初始化方法,在此给选择、上传按钮绑定事件
183			var self = this;  // 克隆一个自身
184			
185			if (this.dragDrop) {
186				this.dragDrop.addEventListener("dragover", function(e) { self.funDragHover(e); }, false);
187				this.dragDrop.addEventListener("dragleave", function(e) { self.funDragHover(e); }, false);
188				this.dragDrop.addEventListener("drop", function(e) { self.funGetFiles(e); }, false);
189			}
190			
191			// 如果选择按钮存在
192			if(self.fileInput){
193				// 绑定change事件
194				this.fileInput.addEventListener("change", function(e) {
195					self.funGetFiles(e); 
196				}, false);	
197			}
198			
199			// 如果上传按钮存在
200			if(self.uploadInput){
201				// 绑定click事件
202				this.uploadInput.addEventListener("click", function(e) {
203					self.funUploadFiles(e); 
204				}, false);	
205			}
206		}
207};
208
Full Screen

uploadFile.js

Source: uploadFile.js Github

copy
1/**
2 * 组件页面对象
3 */
4var UploadFilePluginObj = function (options) {
5
6    this.myDropzone = null;
7    /**
8     * 配置参数
9     */
10    var options = options;
11
12    /**
13     * 文件数组
14     */
15    var successFilePathes = [];
16
17    var addCount = 0;
18
19    var completeCount = 0;
20
21    var processFlag = 0;
22
23    /**
24     * 查看上传进度
25     */
26    function checkProcess() {
27        _global_tools_obj.doAjax("/service/plugins/uploadFile", {
28            oper: "checkprocess",
29            filename: "_uploadfile_plugin_oldfile",
30            processFlag: processFlag
31        }, function (data) {
32            var process = parseInt(data);
33            var prostr = (process / 10) + "%";
34            setTimeout(function () {
35                $("#_uploadfile_plugin_processid").attr("data-percent", prostr);
36                $("#_uploadfile_plugin_processid").children().eq(0).width(prostr);
37            }, 1);
38            processFlag++;
39            checkProcess();
40        }, "POST", false, "text");
41    }
42
43    /**
44     * 初始化上传组件
45     */
46    function initfileinput() {
47        AUI.element.initFileInput("_uploadfile_plugin_oldfile", {
48            no_file: '请选择文件',
49            btn_choose: '选择',
50            btn_change: "重新选择",
51            no_icon: 'ace-icon fa fa-cloud-upload',
52            droppable: false,
53            thumbnail: false,
54            preview_error: function (filename, error_code) {
55                switch (error_code) {
56                    case 1:
57                        AUI.dialog.alert("文件加载失败", null, 3);
58                        break;
59                    case 2:
60                        AUI.dialog.alert("图片加载失败", null, 3);
61                        break;
62                    case 3:
63                        AUI.dialog.alert("临时文件生成失败", null, 3);
64                        break;
65                    default:
66                        AUI.dialog.alert("未知错误", null, 3);
67                }
68            }
69        });
70    }
71
72    /**
73     * 显示老版本浏览器上传组件
74     */
75    function showOldUpload() {
76        var size = options.maxFilesize;
77        if (size / 1024 > 1) {
78            size = (size / 1024) + " MB";
79        } else {
80            size = size + " KB";
81        }
82        $("#_uploadfile_plugin_custom_size").html("文件大小不得超过 <span class='red'>" + size + "</span> 否则将无法成功上传");
83        var filetypetext = "";
84        if (options.acceptedFiles != null) {
85            var filetypes = options.acceptedFiles.split(",");
86            var tmptypes = [];
87            for (var i = 0; i < filetypes.length; i++) {
88                if (filetypes[i].indexOf(".") > -1 && filetypes[i].indexOf(".") == 0) {
89                    tmptypes.push(filetypes[i]);
90                }
91            }
92            if (tmptypes.length == 0) {
93                filetypetext = "无";
94            } else {
95                filetypetext = tmptypes.join(",");
96            }
97        } else {
98            filetypetext = "全部";
99        }
100        $("#_uploadfile_plugin_custom_type").html("允许上传的文件类型:" + filetypetext);
101        $("#_uploadfile_plugin_newBrower").addClass("hidden");
102        $("#_uploadfile_plugin_oldBrower").removeClass("hidden");
103        initfileinput();
104        $("#_uploadfile_plugin_upload_btn").click(function () {
105            if ($.trim($("#_uploadfile_plugin_oldfile").val()) == "") {
106                AUI.dialog.alert("请选择需要上传的文件!", null, 2);
107                return;
108            }
109            if (validateFileType()) {
110                checkProcess();
111                $(this).prop("disabled", true);
112                $("#_uploadfile_plugin_processid").removeClass("hidden");
113                _tools_file_obj.doUploadFileForAjax("_uploadfile_plugin_oldfile", "/service/plugins/uploadFile",
114                    {
115                        oper: "upload",
116                        fileid: "_uploadfile_plugin_oldfile",
117                        path: options.path,
118                        maxFilesize: options.maxFilesize
119                    },
120                    function (url) {
121                        setTimeout(function () {
122                            AUI.dialog.closeDialog($("#_uploadfile_plugin_newBrower"), url);
123                        }, 500);
124                    },
125                    function (message) {
126                        $("#_uploadfile_plugin_processid").addClass("hidden");
127                        $("#_uploadfile_plugin_upload_btn").prop("disabled", false);
128                        AUI.dialog.alert(message, function () {
129                            AUI.dialog.closeDialog($("#_uploadfile_plugin_newBrower"));
130                        }, 3);
131                    });
132            }
133        });
134    }
135
136    /**
137     * 文件类型校验
138     */
139    function validateFileType() {
140        if (options.acceptedFiles == null) {
141            return true;
142        } else {
143            var acceptedFiles = options.acceptedFiles.split(",");
144            for (var i = 0; i < acceptedFiles.length; i++) {
145                if (acceptedFiles[i].indexOf(".") > -1 && acceptedFiles[i].indexOf(".") == 0) {
146                    var filename = $("#_uploadfile_plugin_oldfile").val();
147                    var ext = filename.substring(filename.lastIndexOf("."));
148                    if (ext == acceptedFiles[i]) {
149                        return true;
150                    }
151                }
152            }
153            AUI.dialog.alert("该文件类型不允许上传!", null, 3);
154            return false;
155        }
156    }
157
158    /**
159     * 显示新版浏览器上传组件
160     */
161    this.showUpload = function () {
162        try {
163            Dropzone.autoDiscover = false;
164            var dropzone_options = {
165                url: "/service/plugins/uploadFile?path=" + options.path,
166                maxFilesize: options.maxFilesize / 1024,
167                filesizeBase: 1024,
168                addRemoveLinks: false,
169                parallelUploads: options.parallelUploads,
170                maxFiles: options.maxFiles,
171                acceptedFiles: options.acceptedFiles,
172                dictDefaultMessage: "<span class=\"bigger-150 bolder\">"
173                + "<i class=\"ace-icon fa fa-caret-right red\"></i> "
174                + "拖拽文件至此</span> 进行上传 "
175                + "<span class=\"smaller-80 grey\">(或点击选择)</span> <br /> "
176                + "<i class=\"upload-icon ace-icon fa fa-cloud-upload blue fa-3x\"></i>",
177                dictResponseError: "上传文件出错!",
178                dictInvalidFileType: "该类型文件不允许上传",
179                dictFileTooBig: "文件大小{{filesize}} MB,超过最大限制{{maxFilesize}} MB",
180                dictCancelUpload: "取消上传",
181                dictCancelUploadConfirmation: "确定取消上传该文件?",
182                dictRemoveFile: "删除文件",
183                dictMaxFilesExceeded: "最大允许上传 " + options.maxFiles + " 个文件",
184                previewTemplate: "<div class=\"dz-preview dz-file-preview\">\n  "
185                + "<div class=\"dz-details\">\n    "
186                + "<div class=\"dz-filename\"><span data-dz-name></span></div>\n    "
187                + "<div class=\"dz-size\" data-dz-size></div>\n    "
188                + "<img data-dz-thumbnail />\n  </div>\n  "
189                + "<div class=\"progress progress-small progress-striped active\">"
190                + "<div class=\"progress-bar progress-bar-success\" "
191                + "data-dz-uploadprogress></div></div>\n  "
192                + "<div class=\"dz-success-mark\"><span></span></div>\n  "
193                + "<div class=\"dz-error-mark\"><span></span></div>\n  "
194                + "<div class=\"dz-error-message\">"
195                + "<span data-dz-errormessage></span></div>\n</div>",
196                init: function () {
197                    this.on("addedfile", function () {
198                        addCount++;
199                        $("#_uploadfile_plugin_contrl_upload").removeClass("btn-success").addClass("btn-danger").text("终止上传");
200                    });
201                    this.on("success", function (file, responseText) {
202                        var filepath = $.parseJSON(responseText);
203                        if (filepath.errmsg) {
204                            this.emit("error", file, filepath.errmsg);
205                        } else {
206                            file.path = filepath.filePathName;
207                            successFilePathes.push(filepath.filePathName);
208                            AUI.dialog.setDialogReturn($("#_uploadfile_plugin_newBrower"), successFilePathes.join(";"));
209                        }
210                    });
211                    this.on("complete", function (file) {
212                        completeCount++;
213                        if (completeCount != addCount) {
214                            $("#_uploadfile_plugin_contrl_upload").removeClass("btn-success").addClass("btn-danger").text("终止上传");
215                        } else {
216                            $("#_uploadfile_plugin_contrl_upload").removeClass("btn-danger").addClass("btn-success").text("完成");
217                            $("#_uploadfile_plugin_contrl_upload").prop("disabled", false);
218                        }
219                    });
220                },
221                fallback: function () {
222                    showOldUpload();
223                },
224                canceled: function (file) {
225                    return this.emit("error", file, "文件上传被取消");
226                }
227            };
228            this.myDropzone = new Dropzone("#_uploadfile_plugin_dropzone", dropzone_options);
229        } catch (e) {
230            showOldUpload();
231        }
232    }
233};
234
235$(function () {
236    var obj = new UploadFilePluginObj(AUI.dialog.getParams($("#_uploadfile_plugin_newBrower")));
237    $("#_uploadfile_plugin_contrl_upload").click(function () {
238        var classname = $(this).attr("class");
239        if (classname.indexOf("btn-danger") > -1) {
240            AUI.dialog.confirm("确定终止未完成的任务?", function (data) {
241                if (data) {
242                    var files = obj.myDropzone.getUploadingFiles();
243                    if (files.length > 0) {
244                        $("#_uploadfile_plugin_contrl_upload").prop("disabled", true);
245                    }
246                    for (var i = 0; i < files.length; i++) {
247                        obj.myDropzone.cancelUpload(files[i]);
248                    }
249                }
250            }, true);
251        } else {
252            AUI.dialog.closeDialog($("#_uploadfile_plugin_newBrower"));
253        }
254    });
255    obj.showUpload();
256});
Full Screen

dashboardlogic.js

Source: dashboardlogic.js Github

copy
1const OperatorModel  = require( '../models/operatormodel')
2const { Sequelize, Model, DataTypes } = require('sequelize');
3const { Op, QueryTypes } = require("sequelize");
4
5
6class ReportLogic {
7    
8    static async getMonitoringDashboardInfo(sequelize, startDate, endDate, area)
9    {
10        try{
11            let queryTotalUpload = `SELECT count(*) as totalUpload FROM uploadfile u `  +
12                                    `WHERE u.upload_date BETWEEN '${starDate}' AND '${endDate}'`;
13
14            const result = await sequelize.query("select count(*) as total from uploadfile where uploaded_by_email like '" + uploader + "'", { type: QueryTypes.SELECT });
15
16            return { success: true, payload: result};
17        }
18        catch(err)
19        {
20            return {success: false, error: err, message: err.message}
21        }
22    }
23
24    static async getAllPostersWithPackageItems(sequelize)
25    {
26        try{
27            const posters = await sequelize.query("select * from uploadfile u inner join filepackageitem i " +
28            "on i.upload_file_id = u.id", { type: QueryTypes.SELECT });
29
30            return { success: true, payload: posters};
31        }
32        catch(err)
33        {
34            return {success: false, error: err, message: err.message}
35        }
36    }
37
38    static async getAllPosters(sequelize, offset, limit)
39    {
40        try{
41
42            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'poster'";
43
44            let sql = "select uploadfile.id, uploadfile.filename, " +
45            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.upload_date, " +
46            "count(filepackageitem.upload_file_id) as \"totalItems\" from " +
47            "uploadfile left join " +
48            "filepackageitem on " +
49            "uploadfile.id = filepackageitem.upload_file_id " +
50            "where \"uploadfile\".\"imageCategory\" like 'poster' " +
51            "group by uploadfile.id, uploadfile.filename, " +
52            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.upload_date " +
53            "order by uploadfile.id desc " +
54            "offset " + offset + " limit " + limit;
55
56            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
57            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
58
59            return { success: true, payload: posters, allTotal: totalData};
60        }
61        catch(err)
62        {
63            return {success: false, error: err, message: err.message}
64        }
65    }
66
67    static async getAllPostersByUploader(sequelize, uploader, offset, limit, opt=null)
68    {
69        try{
70
71            let sqlwhere = "";
72            if(opt != null)
73            {
74                if(opt.outlet != "*")
75                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
76
77                if(opt.date != "*")
78                {
79                    let dt = new Date(opt.date).toISOString().slice(0, 10)
80                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
81                }
82                   
83            }
84
85            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'poster' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere;
86
87            let sql = "select uploadfile.id, uploadfile.filename, " +
88            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
89            "count(filepackageitem.upload_file_id) as \"totalItems\" from " +
90            "uploadfile left join " +
91            "filepackageitem on " +
92            "uploadfile.id = filepackageitem.upload_file_id " +
93            "where \"uploadfile\".\"imageCategory\" like 'poster' " +
94            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
95            "group by uploadfile.id, uploadfile.filename, " +
96            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
97            "order by uploadfile.id desc " +
98            "offset " + offset + " limit " + limit;
99
100            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
101            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
102
103            return { success: true, payload: posters, allTotal: totalData};
104        }
105        catch(err)
106        {
107            return {success: false, error: err, message: err.message}
108        }
109    }
110
111    static async getAllPosterBeforeAfterByUploader(sequelize, uploader, offset, limit, opt=null)
112    {
113        try{
114
115            let sqlwhere = "";
116            if(opt != null)
117            {
118                if(opt.outlet != "*")
119                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
120
121                if(opt.date != "*")
122                {
123                    let dt = new Date(opt.date).toISOString().slice(0, 10)
124                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
125                }
126                   
127            }
128
129            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'poster-before-after' and \"uploadfile\".\"beforeAfterType\" like 'before'  and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere;
130
131            let sql = "select uploadfile.id, uploadfile.filename, \"uploadfile\".\"beforeAfterID\", \"uploadfile\".\"beforeAfterType\"," +
132            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
133            "count(filepackageitem.upload_file_id) as \"totalItems\" from " +
134            "uploadfile left join " +
135            "filepackageitem on " +
136            "uploadfile.id = filepackageitem.upload_file_id " +
137            "where \"uploadfile\".\"imageCategory\" like 'poster-before-after'  and \"uploadfile\".\"beforeAfterType\" like 'before' " +
138            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
139            "group by uploadfile.id, uploadfile.filename, " +
140            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
141            "order by uploadfile.id desc " +
142            "offset " + offset + " limit " + limit;
143
144            console.log(sql)
145
146            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
147            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
148
149            return { success: true, payload: posters, allTotal: totalData};
150        }
151        catch(err)
152        {
153            return {success: false, error: err, message: err.message}
154        }
155    }
156
157
158    static async getAllStoreFrontsWithPackageItems(sequelize)
159    {
160        try{
161            const posters = await sequelize.query("select * from uploadfile u inner join storefrontitem i " +
162            "on i.upload_file_id = u.id", { type: QueryTypes.SELECT });
163
164            return { success: true, payload: posters};
165        }
166        catch(err)
167        {
168            return {success: false, error: err, message: err.message}
169        }
170    }
171
172    static async getAllStoreFronts(sequelize, offset, limit)
173    {
174        try{
175
176            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'storefront'";
177
178            let sql = "select uploadfile.id, uploadfile.filename, " +
179            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
180            "count(storefrontitem.upload_file_id) as \"totalItems\" from " +
181            "uploadfile left join " +
182            "storefrontitem on " +
183            "uploadfile.id = storefrontitem.upload_file_id " +
184            "where \"uploadfile\".\"imageCategory\" like 'storefront' " +
185            "group by uploadfile.id, uploadfile.filename, " +
186            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
187            "order by uploadfile.id desc " +
188            "offset " + offset + " limit " + limit;
189
190            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
191            const storefronts = await sequelize.query(sql, { type: QueryTypes.SELECT });
192
193            return { success: true, payload: storefronts, allTotal: totalData};
194        }
195        catch(err)
196        {
197            return {success: false, error: err, message: err.message}
198        }
199    }
200
201    static async getAllStoreFrontsByUploader(sequelize, uploader, offset, limit, opt=null)
202    {
203        try{
204            let sqlwhere = "";
205            if(opt != null)
206            {
207                if(opt.outlet != "*")
208                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
209
210                if(opt.date != "*")
211                {
212                    let dt = new Date(opt.date).toISOString().slice(0, 10)
213                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
214                }
215                   
216            }
217
218            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'storefront' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' "  + sqlwhere;
219
220            let sql = "select uploadfile.id, uploadfile.filename, " +
221            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
222            "count(storefrontitem.upload_file_id) as \"totalItems\" from " +
223            "uploadfile left join " +
224            "storefrontitem on " +
225            "uploadfile.id = storefrontitem.upload_file_id " +
226            "where \"uploadfile\".\"imageCategory\" like 'storefront' " +
227            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
228            "group by uploadfile.id, uploadfile.filename, " +
229            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
230            "order by uploadfile.id desc " +
231            "offset " + offset + " limit " + limit;
232
233            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
234            const storefronts = await sequelize.query(sql, { type: QueryTypes.SELECT });
235
236            return { success: true, payload: storefronts, allTotal: totalData};
237        }
238        catch(err)
239        {
240            return {success: false, error: err, message: err.message}
241        }
242    }
243
244    static async getAllStoreFrontBeforeAfterByUploader(sequelize, uploader, offset, limit, opt=null)
245    {
246        try{
247            let sqlwhere = "";
248            if(opt != null)
249            {
250                if(opt.outlet != "*")
251                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
252
253                if(opt.date != "*")
254                {
255                    let dt = new Date(opt.date).toISOString().slice(0, 10)
256                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
257                }
258                   
259            }
260
261            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'storefront-before-after'  and \"uploadfile\".\"beforeAfterType\" like 'before' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' "  + sqlwhere;
262
263            let sql = "select uploadfile.id, uploadfile.filename, \"uploadfile\".\"beforeAfterID\", \"uploadfile\".\"beforeAfterType\"," +
264            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
265            "count(storefrontitem.upload_file_id) as \"totalItems\" from " +
266            "uploadfile left join " +
267            "storefrontitem on " +
268            "uploadfile.id = storefrontitem.upload_file_id " +
269            "where \"uploadfile\".\"imageCategory\" like 'storefront-before-after  and \"uploadfile\".\"beforeAfterType\" like 'before' " +
270            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
271            "group by uploadfile.id, uploadfile.filename, " +
272            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
273            "order by uploadfile.id desc " +
274            "offset " + offset + " limit " + limit;
275
276            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
277            const storefronts = await sequelize.query(sql, { type: QueryTypes.SELECT });
278
279            return { success: true, payload: storefronts, allTotal: totalData};
280        }
281        catch(err)
282        {
283            return {success: false, error: err, message: err.message}
284        }
285    }
286
287    static async getAllTotalSalesByUploader(sequelize, uploader, offset, limit, opt=null)
288    {
289        try{
290
291            let sqlwhere = "";
292            if(opt != null)
293            {
294                if(opt.outlet != "*")
295                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
296
297                if(opt.date != "*")
298                {
299                    let dt = new Date(opt.date).toISOString().slice(0, 10)
300                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
301                }
302                   
303            }
304
305            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'total-sales' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere;
306
307            let sql = "select uploadfile.id, uploadfile.filename, " +
308            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
309            "count(totalsales.upload_file_id) as \"totalItems\" from " +
310            "uploadfile left join " +
311            "totalsales on " +
312            "uploadfile.id = totalsales.upload_file_id " +
313            "where \"uploadfile\".\"imageCategory\" like 'total-sales' " +
314            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
315            "group by uploadfile.id, uploadfile.filename, " +
316            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
317            "order by uploadfile.id desc " +
318            "offset " + offset + " limit " + limit;
319
320            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
321            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
322
323            return { success: true, payload: posters, allTotal: totalData};
324        }
325        catch(err)
326        {
327            return {success: false, error: err, message: err.message}
328        }
329    }
330
331    static async getAllEtalaseByUploader(sequelize, uploader, offset, limit, opt=null)
332    {
333        try{
334
335            let sqlwhere = "";
336            if(opt != null)
337            {
338                if(opt.outlet != "*")
339                   sqlwhere = " and uploadfile.store_id like '" + opt.outlet + "' ";
340
341                if(opt.date != "*")
342                {
343                    let dt = new Date(opt.date).toISOString().slice(0, 10)
344                    sqlwhere = " and uploadfile.upload_date between '" + dt + " 00:00:00' and '" + dt + " 23:59:59' ";
345                }
346                   
347            }
348
349            let sqlTotal = "select count(*) as total from uploadfile where \"uploadfile\".\"imageCategory\" like 'etalase' and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere;
350
351            let sql = "select uploadfile.id, uploadfile.filename, " +
352            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date, " +
353            "count(etalaseitem.upload_file_id) as \"totalItems\" from " +
354            "uploadfile left join " +
355            "etalaseitem on " +
356            "uploadfile.id = etalaseitem.upload_file_id " +
357            "where \"uploadfile\".\"imageCategory\" like 'etalase' " +
358            "and \"uploadfile\".\"uploaded_by_email\" like '" + uploader + "' " + sqlwhere +
359            "group by uploadfile.id, uploadfile.filename, " +
360            "uploadfile.store_id,uploadfile.store_name,uploadfile.uploaded_by_email, uploadfile.uploaded_filename, uploadfile.upload_date " +
361            "order by uploadfile.id desc " +
362            "offset " + offset + " limit " + limit;
363
364            const totalData = await sequelize.query(sqlTotal, { type: QueryTypes.SELECT });
365            const posters = await sequelize.query(sql, { type: QueryTypes.SELECT });
366
367            return { success: true, payload: posters, allTotal: totalData};
368        }
369        catch(err)
370        {
371            return {success: false, error: err, message: err.message}
372        }
373    }
374}
375
376module.exports = ReportLogic;
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Webdriverio on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)