Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr Moon committed Jan 24, 2022
1 parent 368102d commit 99f9a78
Show file tree
Hide file tree
Showing 8 changed files with 172 additions and 140 deletions.
6 changes: 5 additions & 1 deletion config/app.json
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
{}
{
"app": {
"password": "123456"
}
}
66 changes: 35 additions & 31 deletions public/js/adminMongo.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,74 +89,78 @@ $(document).ready(function(){
$('#export_coll').val($(this).attr('id'));
});

// when docs per page is changed
$(document).on('change', '#docsPerPage', function(){
localStorage.setItem('docsPerPage', $('#docsPerPage').val());
// 페이지뷰 항목수 변경시 콜백 when docs per page is changed
$(document).on('change', '#docsPerPage', function() {
localStorage.setItem( 'docsPerPage', $('#docsPerPage').val() );
window.location = $('#app_context').val() + '/app/' + $('#conn_name').val() + '/' + $('#db_name').val() + '/' + $('#coll_name').val() + '/view/1';
});

// set the URL search parameters
$(document).on('click', '#searchModalAction', function(){
var key_name = $('#search_key_fields option:selected').text();
var val = $('#search_value_value').val();
// 컬렉션 - 도큐먼트 찾기 모달 띄우기 set the URL search parameters
$(document).on('click', '#searchModalAction', function() {
var key_name = $('#search_key_fields option:selected').text();
var val = $('#search_value_value').val();

if(key_name !== '' && val !== ''){
if ( key_name !== '' && val !== '') {
// build the simply key/value query object and call paginate();
var qry_obj = {};

// check if value is a number/integer
var intReg = new RegExp('^[0-9]+$');
if(val.match(intReg)){
val = parseInt(val);
}else{
// if we find an integer wrapped in quotes
if ( val.match( intReg ) ) {
val = parseInt( val );
}
else {
// if we find an integer wrapped in quotes
var strIntReg = new RegExp('^"[0-9]"+$');
if(val.match(strIntReg)){
val = val.replace(/"/g, '');
if ( val.match( strIntReg ) ) {
val = val.replace( /"/g, '' );
}
}

qry_obj[key_name] = val;

// set the object to local storage to be used if page changes
localStorage.setItem('searchQuery', JSON.stringify(qry_obj));
localStorage.setItem( 'searchQuery', JSON.stringify( qry_obj ) );

// check if the key_name is "_id"
if (key_name == '_id')
if ( key_name == '_id' )
{
var query_string = toEJSON.serializeString('{"_id":ObjectId("' + val + '")}');
localStorage.setItem('searchQuery', query_string);
var query_string = toEJSON.serializeString( '{"_id":ObjectId("' + val + '")}' );
localStorage.setItem( 'searchQuery', query_string );
}

// go to page 1 to remove any issues being on page X from another query/view
window.location.href = $('#app_context').val() + '/app/' + $('#conn_name').val() + '/' + $('#db_name').val() + '/' + $('#coll_name').val() + '/view/1';

// close the searchModal
$('#searchModal').modal('hide');
}else{
show_notification('Please enter a key (field) and a value to search for', 'danger');
}
else {
show_notification( 'Please enter a key (field) and a value to search for', 'danger' );
}
});

$(document).on('click', '#coll_name_edit', function(){
// 컬렉션 이름변경 버튼 이벤트
$(document).on('click', '#coll_name_edit', function() {
var newCollName = $('#coll_name_newval').val();
if(newCollName !== ''){
$.ajax({
if ( newCollName !== '' ) {
$.ajax( {
method: 'POST',
url: $('#app_context').val() + '/collection/' + $('#conn_name').val() + '/' + $('#db_name').val() + '/' + $('#coll_name').val() + '/coll_name_edit',
data: {'new_collection_name': newCollName}
data: { 'new_collection_name': newCollName }
})
.done(function(data){
$('#headCollectionName').text(newCollName);
.done( function( data ) {
$('#headCollectionName').text( newCollName );
$('#collectioName').modal('toggle');
localStorage.setItem('message_text', data.msg);
localStorage.setItem( 'message_text', data.msg );
window.location.href = $('#app_context').val() + '/app/' + $('#conn_name').val() + '/' + $('#db_name').val() + '/' + newCollName + '/view?page=1';
})
.fail(function(data){
show_notification(data.responseJSON.msg, 'danger');
.fail( function( data ) {
show_notification( data.responseJSON.msg, 'danger' );
});
}else{
show_notification('Please enter an index', 'danger');
}
else {
show_notification( 'Please enter an index', 'danger' );
}
});

Expand Down
29 changes: 21 additions & 8 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const mongodb = require('mongodb');
const common = require('./common');

// runs on all routes and checks password if one is setup
router.all( '/api/*', common.checkLogin, function (req, res, next){
router.all( '/api/*', common.checkLogin, function ( req, res, next ) {
next();
});

Expand All @@ -17,7 +17,7 @@ router.post( '/api/:conn/:db/:coll/:page', function ( req, res, next ) {

// Check for existance of connection
if ( connection_list[req.params.conn] === undefined ) {
res.status(400).json({'msg': req.i18n.__('Invalid connection name')});
res.status(400).json( {'msg': req.i18n.__('Invalid connection name')} );
}

// Validate database name
Expand All @@ -27,7 +27,11 @@ router.post( '/api/:conn/:db/:coll/:page', function ( req, res, next ) {

// Get DB's form pool
/** @type {mongodb.Db} */
var mongo_db = connection_list[req.params.conn].native.db(req.params.db);
//var mongo_db = connection_list[req.params.conn].native.db(req.params.db);

/** @type {mongodb.MongoClient} */
const mongo_client = connection_list[req.params.conn].native;
const mongo_db = mongo_client.db( req.params.db );

var page_size = docs_per_page;
var page = 1;
Expand Down Expand Up @@ -101,7 +105,7 @@ router.post( '/api/:conn/:db/:coll/:page', function ( req, res, next ) {
});

// Gets monitoring data
router.get( '/api/monitoring/:conn', function (req, res, next){
router.get( '/api/monitoring/:conn', function ( req, res, next ) {
var dayBack = new Date();
dayBack.setDate(dayBack.getDate() - 1);

Expand Down Expand Up @@ -182,10 +186,19 @@ router.get( '/api/monitoring/:conn', function (req, res, next){
uptime = uptime + ' minutes';
}

if(err){
res.status(400).json({'msg': req.i18n.__('Could not get server monitoring')});
}else{
res.status(200).json({data: returnedData, dataRetrieved: serverEvents[0].dataRetrieved, pid: serverEvents[0].pid, version: serverEvents[0].version, uptime: uptime});
if ( err )
{
res.status(400).json( {'msg': req.i18n.__('Could not get server monitoring')} );
}
else
{
res.status(200).json( {
data: returnedData,
dataRetrieved: serverEvents[0].dataRetrieved,
pid: serverEvents[0].pid,
version: serverEvents[0].version,
uptime: uptime
});
}
}
});
Expand Down
Loading

0 comments on commit 99f9a78

Please sign in to comment.