提交 4dacbaf6 编写于 作者: S Sercan

findOne is done, refactored, implementing findOneAndUpdate

上级 86f0da45
......@@ -5,7 +5,7 @@ Template.strSessionConnection = 'connection';
Template.strSessionCollectionNames = 'collectionNames';
Template.strSessionSelectedCollection = 'selectedCollection';
Template.strSessionSelectedQuery = 'selectedQuery';
Template.strSessionSelectedOptions = "selectedCursorOptions";
Template.strSessionSelectedOptions = "selectedOptions";
Template.clearSessions = function () {
Session.set(Template.strSessionCollectionNames, undefined);
......
/* iCheck plugin Square skin, green
----------------------------------- */
.icheckbox_square-green,
.iradio_square-green {
display: inline-block;
*display: inline;
vertical-align: middle;
margin: 0;
padding: 0;
width: 22px;
height: 22px;
background: url(green.png) no-repeat;
border: none;
cursor: pointer;
}
.icheckbox_square-green {
background-position: 0 0;
}
.icheckbox_square-green.hover {
background-position: -24px 0;
}
.icheckbox_square-green.checked {
background-position: -48px 0;
}
.icheckbox_square-green.disabled {
background-position: -72px 0;
cursor: default;
}
.icheckbox_square-green.checked.disabled {
background-position: -96px 0;
}
.iradio_square-green {
background-position: -120px 0;
}
.iradio_square-green.hover {
background-position: -144px 0;
}
.iradio_square-green.checked {
background-position: -168px 0;
}
.iradio_square-green.disabled {
background-position: -192px 0;
cursor: default;
}
.iradio_square-green.checked.disabled {
background-position: -216px 0;
}
/* HiDPI support */
@media (-o-min-device-pixel-ratio: 5/4), (-webkit-min-device-pixel-ratio: 1.25), (min-resolution: 120dpi) {
.icheckbox_square-green,
.iradio_square-green {
background-image: url(green@2x.png);
-webkit-background-size: 240px 24px;
background-size: 240px 24px;
}
}
\ No newline at end of file
/*! iCheck v1.0.2 by Damir Sultanov, http://git.io/arlzeA, MIT Licensed */
(function(f){function A(a,b,d){var c=a[0],g=/er/.test(d)?_indeterminate:/bl/.test(d)?n:k,e=d==_update?{checked:c[k],disabled:c[n],indeterminate:"true"==a.attr(_indeterminate)||"false"==a.attr(_determinate)}:c[g];if(/^(ch|di|in)/.test(d)&&!e)x(a,g);else if(/^(un|en|de)/.test(d)&&e)q(a,g);else if(d==_update)for(var f in e)e[f]?x(a,f,!0):q(a,f,!0);else if(!b||"toggle"==d){if(!b)a[_callback]("ifClicked");e?c[_type]!==r&&q(a,g):x(a,g)}}function x(a,b,d){var c=a[0],g=a.parent(),e=b==k,u=b==_indeterminate,
v=b==n,s=u?_determinate:e?y:"enabled",F=l(a,s+t(c[_type])),B=l(a,b+t(c[_type]));if(!0!==c[b]){if(!d&&b==k&&c[_type]==r&&c.name){var w=a.closest("form"),p='input[name="'+c.name+'"]',p=w.length?w.find(p):f(p);p.each(function(){this!==c&&f(this).data(m)&&q(f(this),b)})}u?(c[b]=!0,c[k]&&q(a,k,"force")):(d||(c[b]=!0),e&&c[_indeterminate]&&q(a,_indeterminate,!1));D(a,e,b,d)}c[n]&&l(a,_cursor,!0)&&g.find("."+C).css(_cursor,"default");g[_add](B||l(a,b)||"");g.attr("role")&&!u&&g.attr("aria-"+(v?n:k),"true");
g[_remove](F||l(a,s)||"")}function q(a,b,d){var c=a[0],g=a.parent(),e=b==k,f=b==_indeterminate,m=b==n,s=f?_determinate:e?y:"enabled",q=l(a,s+t(c[_type])),r=l(a,b+t(c[_type]));if(!1!==c[b]){if(f||!d||"force"==d)c[b]=!1;D(a,e,s,d)}!c[n]&&l(a,_cursor,!0)&&g.find("."+C).css(_cursor,"pointer");g[_remove](r||l(a,b)||"");g.attr("role")&&!f&&g.attr("aria-"+(m?n:k),"false");g[_add](q||l(a,s)||"")}function E(a,b){if(a.data(m)){a.parent().html(a.attr("style",a.data(m).s||""));if(b)a[_callback](b);a.off(".i").unwrap();
f(_label+'[for="'+a[0].id+'"]').add(a.closest(_label)).off(".i")}}function l(a,b,f){if(a.data(m))return a.data(m).o[b+(f?"":"Class")]}function t(a){return a.charAt(0).toUpperCase()+a.slice(1)}function D(a,b,f,c){if(!c){if(b)a[_callback]("ifToggled");a[_callback]("ifChanged")[_callback]("if"+t(f))}}var m="iCheck",C=m+"-helper",r="radio",k="checked",y="un"+k,n="disabled";_determinate="determinate";_indeterminate="in"+_determinate;_update="update";_type="type";_click="click";_touch="touchbegin.i touchend.i";
_add="addClass";_remove="removeClass";_callback="trigger";_label="label";_cursor="cursor";_mobile=/ipad|iphone|ipod|android|blackberry|windows phone|opera mini|silk/i.test(navigator.userAgent);f.fn[m]=function(a,b){var d='input[type="checkbox"], input[type="'+r+'"]',c=f(),g=function(a){a.each(function(){var a=f(this);c=a.is(d)?c.add(a):c.add(a.find(d))})};if(/^(check|uncheck|toggle|indeterminate|determinate|disable|enable|update|destroy)$/i.test(a))return a=a.toLowerCase(),g(this),c.each(function(){var c=
f(this);"destroy"==a?E(c,"ifDestroyed"):A(c,!0,a);f.isFunction(b)&&b()});if("object"!=typeof a&&a)return this;var e=f.extend({checkedClass:k,disabledClass:n,indeterminateClass:_indeterminate,labelHover:!0},a),l=e.handle,v=e.hoverClass||"hover",s=e.focusClass||"focus",t=e.activeClass||"active",B=!!e.labelHover,w=e.labelHoverClass||"hover",p=(""+e.increaseArea).replace("%","")|0;if("checkbox"==l||l==r)d='input[type="'+l+'"]';-50>p&&(p=-50);g(this);return c.each(function(){var a=f(this);E(a);var c=this,
b=c.id,g=-p+"%",d=100+2*p+"%",d={position:"absolute",top:g,left:g,display:"block",width:d,height:d,margin:0,padding:0,background:"#fff",border:0,opacity:0},g=_mobile?{position:"absolute",visibility:"hidden"}:p?d:{position:"absolute",opacity:0},l="checkbox"==c[_type]?e.checkboxClass||"icheckbox":e.radioClass||"i"+r,z=f(_label+'[for="'+b+'"]').add(a.closest(_label)),u=!!e.aria,y=m+"-"+Math.random().toString(36).substr(2,6),h='<div class="'+l+'" '+(u?'role="'+c[_type]+'" ':"");u&&z.each(function(){h+=
'aria-labelledby="';this.id?h+=this.id:(this.id=y,h+=y);h+='"'});h=a.wrap(h+"/>")[_callback]("ifCreated").parent().append(e.insert);d=f('<ins class="'+C+'"/>').css(d).appendTo(h);a.data(m,{o:e,s:a.attr("style")}).css(g);e.inheritClass&&h[_add](c.className||"");e.inheritID&&b&&h.attr("id",m+"-"+b);"static"==h.css("position")&&h.css("position","relative");A(a,!0,_update);if(z.length)z.on(_click+".i mouseover.i mouseout.i "+_touch,function(b){var d=b[_type],e=f(this);if(!c[n]){if(d==_click){if(f(b.target).is("a"))return;
A(a,!1,!0)}else B&&(/ut|nd/.test(d)?(h[_remove](v),e[_remove](w)):(h[_add](v),e[_add](w)));if(_mobile)b.stopPropagation();else return!1}});a.on(_click+".i focus.i blur.i keyup.i keydown.i keypress.i",function(b){var d=b[_type];b=b.keyCode;if(d==_click)return!1;if("keydown"==d&&32==b)return c[_type]==r&&c[k]||(c[k]?q(a,k):x(a,k)),!1;if("keyup"==d&&c[_type]==r)!c[k]&&x(a,k);else if(/us|ur/.test(d))h["blur"==d?_remove:_add](s)});d.on(_click+" mousedown mouseup mouseover mouseout "+_touch,function(b){var d=
b[_type],e=/wn|up/.test(d)?t:v;if(!c[n]){if(d==_click)A(a,!1,!0);else{if(/wn|er|in/.test(d))h[_add](e);else h[_remove](e+" "+t);if(z.length&&B&&e==v)z[/ut|nd/.test(d)?_remove:_add](w)}if(_mobile)b.stopPropagation();else return!1}})})}})(window.jQuery||window.Zepto);
......@@ -18,14 +18,14 @@ Template.browseCollection.onRendered(function () {
});
Template.browseCollection.events({
'change #cmbQueries': function (e) {
'change #cmbQueries': function () {
var value = $('#cmbQueries').find(":selected").text();
if (value) {
Session.set(Template.strSessionSelectedQuery, value);
}
},
'click #btnSwitchView': function (e) {
'click #btnSwitchView': function () {
var jsonView = $('#divJsonEditor');
var aceView = $('#divAceEditor');
......@@ -36,7 +36,14 @@ Template.browseCollection.events({
jsonView.hide();
aceView.show('slow');
}
},
'click #btnExecuteQuery': function () {
var queryTemplate = Session.get(Template.strSessionSelectedQuery);
if (queryTemplate) {
Template[queryTemplate].executeQuery();
}else{
Template["find"].executeQuery();
}
}
});
......@@ -59,7 +66,7 @@ Template.browseCollection.initExecuteQuery = function () {
var l = $('#btnExecuteQuery').ladda();
l.ladda('start');
return l;
}
};
Template.browseCollection.setResult = function (result) {
// set json editor
......@@ -90,4 +97,4 @@ Template.browseCollection.getEditor = function () {
});
}
return jsonEditor;
}
\ No newline at end of file
};
\ No newline at end of file
......@@ -8,14 +8,6 @@ Template.find.onRendered(function () {
Template.find.initializeSessionVariable();
});
//TODO change this
Template.browseCollection.events({
'click #btnExecuteQuery': function (e) {
Template.find.executeQuery();
}
});
Template.find.initializeAceEditor = function () {
AceEditor.instance("preSelector", {
mode: "javascript",
......@@ -24,7 +16,7 @@ Template.find.initializeAceEditor = function () {
editor.$blockScrolling = Infinity;
editor.setOptions({
fontSize: "11pt",
showPrintMargin: false,
showPrintMargin: false
});
// remove newlines in pasted text
......@@ -42,7 +34,7 @@ Template.find.initializeAceEditor = function () {
// disable Enter Shift-Enter keys
editor.commands.bindKey("Enter|Shift-Enter", Template.find.executeQuery);
});
}
};
Template.find.initializeOptions = function () {
var cmb = $('#cmbCursorOptions');
......@@ -54,7 +46,7 @@ Template.find.initializeOptions = function () {
cmb.chosen();
Template.find.setCursorOptionsChangeEvent(cmb);
}
};
Template.find.setCursorOptionsChangeEvent = function (cmb) {
cmb.on('change', function (evt, params) {
......@@ -67,11 +59,11 @@ Template.find.setCursorOptionsChangeEvent = function (cmb) {
}
Session.set(Template.strSessionSelectedOptions, array);
});
}
};
Template.find.initializeSessionVariable = function () {
Session.set(Template.strSessionSelectedOptions, []);
}
};
Template.find.executeQuery = function (methodName) {
var laddaButton = Template.browseCollection.initExecuteQuery();
......@@ -118,91 +110,91 @@ Template.find.executeQuery = function (methodName) {
// stop loading animation
laddaButton.ladda('stop');
});
}
};
Template.find.getCursorOptions = function () {
var result = {};
if ($.inArray("PROJECT", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = ace.edit("aceProject").getSession().getValue();
if (!val) {
val = {};
var projectVal = ace.edit("aceProject").getSession().getValue();
if (!projectVal) {
projectVal = {};
}
else {
try {
val = JSON.parse(val);
projectVal = JSON.parse(projectVal);
}
catch (err) {
result["ERROR"] = "Syntax Error on $project: " + err.message;
return result;
}
}
result[CURSOR_OPTIONS.PROJECT] = val;
result[CURSOR_OPTIONS.PROJECT] = projectVal;
}
if ($.inArray("SKIP", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = $('#inputSkip').val();
if (val) {
result[CURSOR_OPTIONS.SKIP] = parseInt(val);
var skipVal = $('#inputSkip').val();
if (skipVal) {
result[CURSOR_OPTIONS.SKIP] = parseInt(skipVal);
}
}
if ($.inArray("LIMIT", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = $('#inputLimit').val();
if (val) {
result[CURSOR_OPTIONS.LIMIT] = parseInt(val);
var limitVal = $('#inputLimit').val();
if (limitVal) {
result[CURSOR_OPTIONS.LIMIT] = parseInt(limitVal);
}
}
if ($.inArray("MAX", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = ace.edit("aceMax").getSession().getValue();
if (!val) {
val = {};
var maxVal = ace.edit("aceMax").getSession().getValue();
if (!maxVal) {
maxVal = {};
}
else {
try {
val = JSON.parse(val);
maxVal = JSON.parse(maxVal);
}
catch (err) {
result["ERROR"] = "Syntax Error on $max: " + err.message;
return result;
}
}
result[CURSOR_OPTIONS.MAX] = val;
result[CURSOR_OPTIONS.MAX] = maxVal;
}
if ($.inArray("MIN", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = ace.edit("aceMin").getSession().getValue();
if (!val) {
val = {};
var minVal = ace.edit("aceMin").getSession().getValue();
if (!minVal) {
minVal = {};
}
else {
try {
val = JSON.parse(val);
minVal = JSON.parse(minVal);
}
catch (err) {
result["ERROR"] = "Syntax Error on $min: " + err.message;
return result;
}
}
result[CURSOR_OPTIONS.MIN] = val;
result[CURSOR_OPTIONS.MIN] = minVal;
}
if ($.inArray("SORT", Session.get(Template.strSessionSelectedOptions)) != -1) {
var val = ace.edit("aceSort").getSession().getValue();
if (!val) {
val = {};
var sortVal = ace.edit("aceSort").getSession().getValue();
if (!sortVal) {
sortVal = {};
}
else {
try {
val = JSON.parse(val);
sortVal = JSON.parse(sortVal);
}
catch (err) {
result["ERROR"] = "Syntax Error on $sort: " + err.message;
return result;
}
}
result[CURSOR_OPTIONS.SORT] = val;
result[CURSOR_OPTIONS.SORT] = sortVal;
}
return result;
}
\ No newline at end of file
};
\ No newline at end of file
......@@ -25,4 +25,4 @@ Template.findOne.initializeOptions = function () {
Template.findOne.executeQuery = function () {
Template.find.executeQuery('findOne');
}
\ No newline at end of file
};
\ No newline at end of file
<template name="findOneModifyOptions">
<div class="form-group">
<label class="col-lg-1 control-label">Selector</label>
<div class="col-lg-11">
<pre class="form-control" id='preSelector'></pre>
<span class="help-block m-b-none">You can use <strong>string</strong> to query <strong>ISODate</strong> and <strong>ObjectID</strong>, date format is <strong>DD.MM.YYYY
HH:mm:ss</strong></span>
</div>
</div>
<div class="form-group">
<label class="col-lg-1 control-label">Options</label>
<div class="col-lg-11">
<select id="cmbFindOneOptions"
data-placeholder="Choose one or more options.."
multiple="true"
class="chosen-select form-control"
tabindex="-1">
</select>
</div>
</div>
{{> findOneModifyOptions}}
</template>
\ No newline at end of file
......@@ -30,7 +30,7 @@
<template name="limit">
<div class="form-group">
<label class="col-lg-1 control-label">limit</label>
<label class="col-lg-1 control-label" labelfo>limit</label>
<div class="col-lg-11">
<input id="inputLimit" min="0" required="true" type="number" class="form-control">
</div>
......
......@@ -3,10 +3,7 @@
*/
Template.cursorOptions.helpers({
'isSelected': function (option) {
if ($.inArray(option, Session.get(Template.strSessionSelectedOptions)) != -1) {
return true;
}
return false;
return $.inArray(option, Session.get(Template.strSessionSelectedOptions)) != -1;
}
});
......@@ -34,7 +31,7 @@ Template.cursorOptions.initializeAceEditor = function (id) {
editor.$blockScrolling = Infinity;
editor.setOptions({
fontSize: "11pt",
showPrintMargin: false,
showPrintMargin: false
});
// remove newlines in pasted text
......@@ -60,4 +57,4 @@ Template.cursorOptions.initializeAceEditor = function (id) {
editor.commands.bindKey("Enter|Shift-Enter", Template.findOne.executeQuery);
}
});
}
\ No newline at end of file
};
\ No newline at end of file
<template name="findOneModifyOptions">
{{#if isSelected "PROJECT"}}
{{> project}}
{{/if}}
{{#if isSelected "SORT"}}
{{> sort}}
{{/if}}
{{#if isSelected "UPSERT"}}
{{> upsert}}
{{/if}}
{{#if isSelected "RETURN_ORIGINAL"}}
{{> returnOriginal}}
{{/if}}
</template>
<template name="project">
<div class="form-group">
<label class="col-lg-1 control-label">project</label>
<div class="col-lg-11">
<pre class="form-control" id='aceProject'></pre>
</div>
</div>
</template>
<template name="sort">
<div class="form-group">
<label class="col-lg-1 control-label">sort</label>
<div class="col-lg-11">
<pre class="form-control" id='aceSort'></pre>
</div>
</div>
</template>
<template name="upsert">
<div class="form-group">
<label class="col-lg-1 control-label">upsert</label>
<div class="col-lg-11">
<!--TODO ICHECKBOX GELECEK-->
</div>
</div>
</template>
<template name="returnOriginal">
<div class="form-group">
<label class="col-lg-1 control-label">returnOriginal</label>
<div class="col-lg-11">
<!--TODO ICHECKBOX GELECEK-->
</div>
</div>
</template>
\ No newline at end of file
/**
* Created by RSercan on 1.1.2016.
*/
Template.findOneModifyOptions.helpers({
'isSelected': function (option) {
return $.inArray(option, Session.get(Template.strSessionSelectedOptions)) != -1;
}
});
Template.project.onRendered(function () {
Template.findOneModifyOptions.initializeAceEditor('aceProject');
});
Template.sort.onRendered(function () {
Template.findOneModifyOptions.initializeAceEditor('aceSort');
});
Template.findOneModifyOptions.initializeAceEditor = function (id) {
AceEditor.instance(id, {
mode: "javascript",
theme: 'dawn'
}, function (editor) {
editor.$blockScrolling = Infinity;
editor.setOptions({
fontSize: "11pt",
showPrintMargin: false
});
// remove newlines in pasted text
editor.on("paste", function (e) {
e.text = e.text.replace(/[\r\n]+/g, " ");
});
// make mouse position clipping nicer
editor.renderer.screenToTextCoordinates = function (x, y) {
var pos = this.pixelToScreenCoordinates(x, y);
return this.session.screenToDocumentPosition(
Math.min(this.session.getScreenLength() - 1, Math.max(pos.row, 0)),
Math.max(pos.column, 0)
);
};
// disable Enter Shift-Enter keys and bind to executeQuery for corresponding template
//var name = Template.instance().parentTemplate(2).view.name;
//var cleanName = name.substring(name.indexOf('.') + 1);
//if (cleanName == QUERY_TYPES.FIND) {
// editor.commands.bindKey("Enter|Shift-Enter", Template.find.executeQuery);
//}
//else if (cleanName == QUERY_TYPES.FINDONE) {
// editor.commands.bindKey("Enter|Shift-Enter", Template.findOne.executeQuery);
//}
});
};
\ No newline at end of file
......@@ -3,8 +3,9 @@
*/
QUERY_TYPES = {
FIND: "find",
FINDONE: "findOne"
}
FINDONE: "findOne",
FINDONE_AND_UPDATE: "findOneAndUpdate"
};
CURSOR_OPTIONS = {
PROJECT: "project",
......@@ -13,4 +14,11 @@ CURSOR_OPTIONS = {
LIMIT: "limit",
MAX: "max",
MIN: "min"
}
\ No newline at end of file
};
FINDONE_MODIFY_OPTIONS = {
PROJECT: "project",
SORT: "sort",
UPSERT: "upsert",
RETURN_ORIGINAL: "returnOriginal"
};
\ No newline at end of file
......@@ -7,7 +7,7 @@ Meteor.methods({
console.log('connecting to : ' + connectionUrl);
var mongodbApi = Meteor.npmRequire('mongodb').MongoClient;
var collectionNames = Async.runSync(function (done) {
return Async.runSync(function (done) {
mongodbApi.connect(connectionUrl, function (err, db) {
if (db == null || db == undefined) {
console.log('could not connect, db is null');
......@@ -20,8 +20,6 @@ Meteor.methods({
}
});
});
return collectionNames;
},
'findOne': function (connection, selectedCollection, selector, cursorOptions) {
......@@ -32,11 +30,15 @@ Meteor.methods({
return proceedFindQuery(connection, selectedCollection, selector, cursorOptions);
},
'findOneAndUpdate': function (connection, selectedCollection, selector, options) {
},
'dropDB': function (connection) {
var connectionUrl = getConnectionUrl(connection);
var mongodbApi = Meteor.npmRequire('mongodb').MongoClient;
var result = Async.runSync(function (done) {
return Async.runSync(function (done) {
mongodbApi.connect(connectionUrl, function (err, db) {
db.dropDatabase(function (err, result) {
db.close();
......@@ -44,8 +46,6 @@ Meteor.methods({
});
});
});
return result;
}
});
......@@ -91,4 +91,4 @@ var proceedFindQuery = function (connection, selectedCollection, selector, curso
convertBSONtoJSON(result);
return result;
}
\ No newline at end of file
};
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册