<commit_before>var me = {
	id: undefined,
	selectedRoomToEnter: undefined,
	enteredRoom: undefined
};

/**
 * Function from which we demand respond, recall,
 * giving them as parameters functions which need to be recalled
 * after receiving expected data.
 */
var main = {
	/**
	 * @function main.userCallback
	 * Types way of sending action callback to user.
	 * By now it's an alert, but allows easy change.
	 */
	userCallback: function(message) {
		alert(message);
	},

	/**
	 * @function main.takePicture
	 * Take picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	takePicture: function(quality) {
		devices.camera.takePicture(quality, function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			//main.addNewMyData('image', imageSrc);
			//var image = document.getElementById('myImageCamera');
			//image.style.display = 'block';

			//image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.loadPicture
	 * Load picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	loadPicture: function() {
		devices.photoLibrary.take(function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			var image = document.getElementById('myImageCamera');
			image.style.display = 'block';

			image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.initialQrCode
	 * Scan QR Code of webmaster, get connection of websocket and save scaned data to input
	 */
	initialQrCode: function() {
		devices.qrCode.scan(function(result) {

			main.setUrl(result);

		}, true);
	},

	/**
	 * @function main.getMac
	 * Download data of device mac and recall with this mac an alert
	 */
	getMac: function() {
		devices.mac.get(function(result) {
			alert(result);
		});
	},

	/**
	 * @function main.getRooms
	 * Download data of rooms
	 */
	getRooms: function() {
		connection.action.getRooms(function(received) {
			// received zawiera listę elementów, np. {id: 0, name: 'room', folderName: 'room'}
			// instersuje nas id po którym dołączamy i name które wyświetlamy
			if (received.length > 0) {
				main.selectRoomToEnter(received[0].id);
			}
			storage.showRooms(received);

		});
	},

	/**
	 * @function main.initUrl
	 * Initialize url
	 */
	initUrl: function() {
		load('connecting');
		connection.initUrl(function() {
			connection.action.home(function(data) {
				if (data.id) {
					historyObj.addTohistoryObj('login');
					load('rooms', true);
				} else {
					load('login', true);
				}
			});
        }, function() {
            load('connection');
        });
	},

	/**
	 * @function main.initSocket
	 * Initialize socket
	 */
	initSocket: function() {
		load('wall');
		connection.socket.init(function() {
			connection.state = connection.states.established;
		}, function() {
			// Here we do not have to type second argument, because
			// It changes *.html page and this new page loads rooms with argument.
			load('rooms');
		});
		connection.socket.ping();
	},

	/**
	 * @function main.setUrl
	 * Set url to login
	 * @param {String} link
	 * link to login
	 */
	setUrl: function(link) {
        load('connecting');
		if (!(link.substring(link.length - 5) === '/api/')) {
			if (link.substring(link.length - 4) === '/api') {
				link = link + '/';
			} else if (link.substring(link.length - 1) === '/') {
				link = link + 'api/';
			} else {
				link = link + '/api/';
			}
		}

		var url = document.getElementById('url');
		url.value = link;
		connection.setUrl(link, function() {
			url.value = link;

			load('login', true);
		}, function() {
            load('connection', true);
		});
	},

	/**
	 * @function main.login
	 * Login to system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 */
	login: function(login, password) {
		connection.action.login(login, password, function(received) {
			if (received.name === login) {//when everything is correct
				me.id = received.id;
				storage.setUserLogin(login);
				storage.setUserPassword(password);
				load('rooms', true);
			}
		}, function(data) { //in case of wrong input data
			main.userCallback('Wrong username or password');
		});
	},

	/**
	 * @function main.login
	 * Register in system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 * @param {String} password2
	 * user password (confirmation)
	 */
	register: function(login, password, password2) {
		connection.action.register(login, password, password2, function(received) {
			if (received) {//when everything is correct
				load('login', true);
			}
		}, function(data) {//in case of wrong input data or data already exist in database
			if (data) {
				main.userCallback(data);
			} else {
				main.userCallback('Login already registered');
			}
		});
	},

	/**
	 * @function main.createRoom
	 * Create room
	 * @param {String} roomName
	 * Name of the room which user want to createElement
	 */
	createRoom: function(roomName) {
		main.selectRoomToEnter();
		connection.action.createRoom(roomName, function(received) {
			var roomId = received.id;
			console.log(JSON.stringify(received));
			main.joinRoom(received, function(answer) {
				callback(answer);
				if (answer) {
					main.userCallback('Room successfully created');
				} else {
					main.userCallback('Creating room failed');
				}
			});
		});
	},

	/**
	 * @function main.joinRoom
	 * Join and enter to current room
	 * @param {int} roomId
	 * ID of current room
	 * @param {} callb
	 */
	joinRoom: function(roomId, callb) {
		if (roomId) {
			connection.action.joinRoom(roomId.id, function(received) {
				if (received) {
					storage.addCreatedRoom(roomId);
					if (callb) {
						callb(received);
					}
				}
			});
		}
	},

	/**
	 * @function main.joinRoomById
	 * Join and and go to wall of typed room
	 * @param {int} roomId
	 * ID of selected room
	 */
	joinRoomById: function(roomId) {
		main.joinRoom({id: roomId, name: 'already typed room'}, function(answer) {
			main.goToWall();
		});
	},

	/**
	 * @function main.selectRoomToEnter
	 * Set room to which one user want to join
	 * @param {int} selectRoomToEnter
	 * User chosen room
	 */
	selectRoomToEnter: function(selectedRoomToEnter) {
		me.selectedRoomToEnter = selectedRoomToEnter;
	},

	/**
	 * @function main.goToWall
	 * Move to wall view
	 */
	goToWall: function() {
		var roomToEnter = storage.getSelectedRoomToEnter();
		main.selectRoomToEnter(roomToEnter);
		if (me.selectedRoomToEnter) {
			window.localStorage.setItem('selectedRoomToEnter', me.selectedRoomToEnter);
			load('wall');
		} else {
			main.userCallback('No room is selected');
		}
	},

	/**
	 * @function main.goToOnlineUsers
	 * Present list of online users
	 */
	goToOnlineUsers: function() {
		load('users', true);
	},

	/**
	 * @function main.enterRoom
	 * Inform the server that user enter to already joined room.
	 * Runned on the wall page, after receiving ping answer.
	 */
	enterRoom: function() {
		var roomId = window.localStorage.getItem('selectedRoomToEnter');
		if (roomId) {
			me.selectedRoomToEnter = roomId;
			connection.socket.enterRoom(roomId);
		} else {
			main.userCallback('No room is selected');
		}
	},

	/**
	 * @function main.scanRoomQrCode
	 * Scan QR code to current room and join this room.
	 * Immediately goes to wall.
	 */
	scanRoomQrCode: function() {
		// scan
		devices.qrCode.scan(function(roomId) {
			main.joinRoomById(roomId);
		});
	},

	/**
	 * @function main.getRoomData
	 * Download all of current room data
	 */
	getRoomData: function() {
		connection.action.getRoomData(function(data) {
			callback('getRoomData' + JSON.stringify(data));
			storage.addAllRoomData(data);
		});
	}
};

/**
 * @function routing.registerAction
 * Get rooms
 * Get room data (wall)
 * Present wall data
 */
routing.registerAction('rooms', function() {
	main.getRooms();
});
routing.registerAction('wall', function() {
	// Here should be displaying room name from storage
	// (which was set in connection.socket.receive.onEnterRoom())

	connection.socket.getConnectedUsers();
	main.getRoomData();

    load('wallContent', true);
});
routing.registerAction('wallContent', function() {
	//storage.* - action of setting view after changing view
	// to set it again
});
routing.registerAction('users', function() {
	storage.showOnlineUsers();
});
routing.registerAction('login', function() {
	//storage.initLoginData
});
routing.registerAction('connection', function() {
	// we can add here any additional connection information
	// to connection page
	main.userCallback('Connection failed');
});

/**
 * @function connection.socket.receive.onEnterRoom
 * Load wall to get data while user entered the current room
 * @param {int, String} data
 * Data consists of meetingID and name
 */
connection.socket.receive.onEnterRoom = function(data) {
	// Here we should assign data to storage
	me.enteredRoom = data;
	load('wall', true);
};

/**
 * @function connection.socket.receive.onPing
 * Get data while user Ping
 */
connection.socket.receive.onPing = function() {
    main.enterRoom();
};

/**
 * Elements received from websocket is supported by functions below:
 */
/**
 * @function connection.socket.receive.onUsersOnline
 * Add new user to OnlineUsers
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onUsersOnline = function(data) {
	callback('onUsersOnline ' + JSON.stringify(data));
	storage.getAllOnlineUsers(data);
	// add new users
};

/**
 * @function connection.socket.receive.onNewUser
 * Alert about new user online
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onNewUser = function(data) {
	callback('onNewUser ' + JSON.stringify(data));
	storage.addNewUser(data);
	// add new user
};

/**
 * @function connection.socket.receive.onRemoveUser
 * Delete user from OnlineUsers list
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onRemoveUser = function(data) {
	callback('onRemoveUser ' + JSON.stringify(data));
	storage.deleteUser(data);
	// remove user
};

/**
 * @function connection.socket.receive.onNewPhoto
 * Alert about new photo
 * @param {} data
 * Data which contain information about photo
 */
connection.socket.receive.onNewPhoto = function(data) {
	callback('onNewPhoto: ' + JSON.stringify(data));
    storage.addNewData(data);
};

/**
 * @function connection.socket.receive.onNewNote
 * Alert about new note
 * @param {} data
 * Data which contain information about note
 */
connection.socket.receive.onNewNote = function(data) {
	callback('onNewNote: ' + JSON.stringify(data));
    storage.addNewData(data);
};

/**
 * @function connection.socket.receive.onNewComment
 * Alert about new comment
 * @param {} data
 * Data which contain information about comment
 */
connection.socket.receive.onNewComment = function(data) {
	callback('onNewComment: ' + JSON.stringify(data));
	storage.addNewData(data);
    // add new comment
};
<commit_msg>client: kosmetyczne zmiany po review<commit_after>var me = {
	id: undefined,
	selectedRoomToEnter: undefined,
	enteredRoom: undefined
};

/**
 * Function from which we demand respond, recall,
 * giving them as parameters functions which need to be recalled
 * after receiving expected data.
 */
var main = {
	/**
	 * @function main.userCallback
	 * Types way of sending action callback to user.
	 * By now it's an alert, but allows easy change.
	 */
	userCallback: function(message) {
		alert(message);
	},

	/**
	 * @function main.takePicture
	 * Take picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	takePicture: function(quality) {
		devices.camera.takePicture(quality, function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			//main.addNewMyData('image', imageSrc);
			//var image = document.getElementById('myImageCamera');
			//image.style.display = 'block';

			//image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.loadPicture
	 * Load picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	loadPicture: function() {
		devices.photoLibrary.take(function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			var image = document.getElementById('myImageCamera');
			image.style.display = 'block';

			image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.initialQrCode
	 * Scan QR Code of webmaster, get connection of websocket and save scaned data to input
	 */
	initialQrCode: function() {
		devices.qrCode.scan(function(result) {

			main.setUrl(result);

		}, true);
	},

	/**
	 * @function main.getMac
	 * Download data of device mac and recall with this mac an alert
	 */
	getMac: function() {
		devices.mac.get(function(result) {
			alert(result);
		});
	},

	/**
	 * @function main.getRooms
	 * Download data of rooms
	 */
	getRooms: function() {
		connection.action.getRooms(function(received) {
			// received zawiera listę elementów, np. {id: 0, name: 'room', folderName: 'room'}
			// instersuje nas id po którym dołączamy i name które wyświetlamy
			if (received.length > 0) {
				main.selectRoomToEnter(received[0].id);
			}
			storage.showRooms(received);

		});
	},

	/**
	 * @function main.initUrl
	 * Initialize url
	 */
	initUrl: function() {
		load('connecting');
		connection.initUrl(function() {
			connection.action.home(function(data) {
				if (data.id) {
					historyObj.addTohistoryObj('login');
					load('rooms', true);
				} else {
					load('login', true);
				}
			});
        }, function() {
            load('connection');
        });
	},

	/**
	 * @function main.initSocket
	 * Initialize socket
	 */
	initSocket: function() {
		load('wall');
		connection.socket.init(function() {
			connection.state = connection.states.established;
		}, function() {
			// Here we do not have to type second argument, because
			// It changes *.html page and this new page loads rooms with argument.
			load('rooms');
		});
		connection.socket.ping();
	},

	/**
	 * @function main.setUrl
	 * Set url to login
	 * @param {String} link
	 * link to login
	 */
	setUrl: function(link) {
        load('connecting');
		if (!(link.substring(link.length - 5) === '/api/')) {
			if (link.substring(link.length - 4) === '/api') {
				link = link + '/';
			} else if (link.substring(link.length - 1) === '/') {
				link = link + 'api/';
			} else {
				link = link + '/api/';
			}
		}

		var url = document.getElementById('url');
		url.value = link;
		connection.setUrl(link, function() {
			url.value = link;

			load('login', true);
		}, function() {
            load('connection', true);
		});
	},

	/**
	 * @function main.login
	 * Login to system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 */
	login: function(login, password) {
		connection.action.login(login, password, function(received) {
			if (received.name === login) {//when everything is correct
				me.id = received.id;
				storage.setUserLogin(login);
				storage.setUserPassword(password);
				load('rooms', true);
			}
		}, function(data) { //in case of wrong input data
			main.userCallback('Wrong username or password');
		});
	},

	/**
	 * @function main.login
	 * Register in system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 * @param {String} password2
	 * user password (confirmation)
	 */
	register: function(login, password, password2) {
		connection.action.register(login, password, password2, function(received) {
			if (received) {//when everything is correct
				load('login', true);
			}
		}, function(data) {//in case of wrong input data or data already exist in database
			if (data) {
				main.userCallback(data);
			} else {
				main.userCallback('Login already registered');
			}
		});
	},

	/**
	 * @function main.createRoom
	 * Create room
	 * @param {String} roomName
	 * Name of the room which user want to createElement
	 */
	createRoom: function(roomName) {
		main.selectRoomToEnter();
		connection.action.createRoom(roomName, function(received) {
			main.joinRoom(received, function(answer) {
				callback(answer);
				if (answer) {
					main.userCallback('Room successfully created');
				} else {
					main.userCallback('Creating room failed');
				}
			});
		});
	},

	/**
	 * @function main.joinRoom
	 * Join and enter to current room
	 * @param {int} room
	 * Data of current room
	 * @param {} callb
	 */
	joinRoom: function(room, callb) {
		if (room) {
			connection.action.joinRoom(room.id, function(received) {
				if (received) {
					storage.addCreatedRoom(room);
					if (callb) {
						callb(received);
					}
				}
			});
		}
	},

	/**
	 * @function main.joinRoomById
	 * Join and and go to wall of typed room
	 * @param {int} roomId
	 * ID of selected room
	 */
	joinRoomById: function(roomId) {
		main.joinRoom({id: roomId, name: 'already typed room'}, function(answer) {
			main.goToWall();
		});
	},

	/**
	 * @function main.selectRoomToEnter
	 * Set room to which one user want to join
	 * @param {int} selectRoomToEnter
	 * User chosen room
	 */
	selectRoomToEnter: function(selectedRoomToEnter) {
		me.selectedRoomToEnter = selectedRoomToEnter;
	},

	/**
	 * @function main.goToWall
	 * Move to wall view
	 */
	goToWall: function() {
		var roomToEnter = storage.getSelectedRoomToEnter();
		main.selectRoomToEnter(roomToEnter);
		if (me.selectedRoomToEnter) {
			window.localStorage.setItem('selectedRoomToEnter', me.selectedRoomToEnter);
			load('wall');
		} else {
			main.userCallback('No room is selected');
		}
	},

	/**
	 * @function main.goToOnlineUsers
	 * Present list of online users
	 */
	goToOnlineUsers: function() {
		load('users', true);
	},

	/**
	 * @function main.enterRoom
	 * Inform the server that user enter to already joined room.
	 * Runned on the wall page, after receiving ping answer.
	 */
	enterRoom: function() {
		var roomId = window.localStorage.getItem('selectedRoomToEnter');
		if (roomId) {
			me.selectedRoomToEnter = roomId;
			connection.socket.enterRoom(roomId);
		} else {
			main.userCallback('No room is selected');
		}
	},

	/**
	 * @function main.scanRoomQrCode
	 * Scan QR code to current room and join this room.
	 * Immediately goes to wall.
	 */
	scanRoomQrCode: function() {
		// scan
		devices.qrCode.scan(function(roomId) {
			main.joinRoomById(roomId);
		});
	},

	/**
	 * @function main.getRoomData
	 * Download all of current room data
	 */
	getRoomData: function() {
		connection.action.getRoomData(function(data) {
			callback('getRoomData' + JSON.stringify(data));
			storage.addAllRoomData(data);
		});
	}
};

/**
 * @function routing.registerAction
 * Get rooms
 * Get room data (wall)
 * Present wall data
 */
routing.registerAction('rooms', function() {
	main.getRooms();
});
routing.registerAction('wall', function() {
	// Here should be displaying room name from storage
	// (which was set in connection.socket.receive.onEnterRoom())

	connection.socket.getConnectedUsers();
	main.getRoomData();

    load('wallContent', true);
});
routing.registerAction('wallContent', function() {
	//storage.* - action of setting view after changing view
	// to set it again
});
routing.registerAction('users', function() {
	storage.showOnlineUsers();
});
routing.registerAction('login', function() {
	//storage.initLoginData
});
routing.registerAction('connection', function() {
	// we can add here any additional connection information
	// to connection page
	main.userCallback('Connection failed');
});

/**
 * @function connection.socket.receive.onEnterRoom
 * Load wall to get data while user entered the current room
 * @param {int, String} data
 * Data consists of meetingID and name
 */
connection.socket.receive.onEnterRoom = function(data) {
	// Here we should assign data to storage
	me.enteredRoom = data;
	load('wall', true);
};

/**
 * @function connection.socket.receive.onPing
 * Get data while user Ping
 */
connection.socket.receive.onPing = function() {
    main.enterRoom();
};

/**
 * Elements received from websocket is supported by functions below:
 */
/**
 * @function connection.socket.receive.onUsersOnline
 * Add new user to OnlineUsers
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onUsersOnline = function(data) {
	callback('onUsersOnline ' + JSON.stringify(data));
	storage.getAllOnlineUsers(data);
	// add new users
};

/**
 * @function connection.socket.receive.onNewUser
 * Alert about new user online
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onNewUser = function(data) {
	callback('onNewUser ' + JSON.stringify(data));
	storage.addNewUser(data);
	// add new user
};

/**
 * @function connection.socket.receive.onRemoveUser
 * Delete user from OnlineUsers list
 * @param {} data
 * Data which contain user data
 */
connection.socket.receive.onRemoveUser = function(data) {
	callback('onRemoveUser ' + JSON.stringify(data));
	storage.deleteUser(data);
	// remove user
};

/**
 * @function connection.socket.receive.onNewPhoto
 * Alert about new photo
 * @param {} data
 * Data which contain information about photo
 */
connection.socket.receive.onNewPhoto = function(data) {
	callback('onNewPhoto: ' + JSON.stringify(data));
    storage.addNewData(data);
};

/**
 * @function connection.socket.receive.onNewNote
 * Alert about new note
 * @param {} data
 * Data which contain information about note
 */
connection.socket.receive.onNewNote = function(data) {
	callback('onNewNote: ' + JSON.stringify(data));
    storage.addNewData(data);
};

/**
 * @function connection.socket.receive.onNewComment
 * Alert about new comment
 * @param {} data
 * Data which contain information about comment
 */
connection.socket.receive.onNewComment = function(data) {
	callback('onNewComment: ' + JSON.stringify(data));
	storage.addNewData(data);
    // add new comment
};
<|endoftext|>


<commit_before>var me = {
	id: undefined,
	chosedRoomToEnter: undefined,
	enteredRoom: undefined
};

/**
 * Function from which we demand respond, recall,
 * giving them as parameters functions which need to be recalled
 * after receiving expected data.
 */
var main = {
	/**
	 * @function main.takePicture
	 * Take picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	takePicture: function(quality) {
		devices.camera.takePicture(quality, function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			//main.addNewMyData('image', imageSrc);
			//var image = document.getElementById('myImageCamera');
			//image.style.display = 'block';

			//image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.loadPicture
	 * Load picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	loadPicture: function() {
		devices.photoLibrary.take(function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			var image = document.getElementById('myImageCamera');
			image.style.display = 'block';

			image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	 /**
	 * @function main.initialQrCode
	 * Scan QR Code of webmaster, get connection of websocket and save scaned data to input
	 */
	initialQrCode: function() {
		devices.qrCode.scan(function(result) {

			main.setUrl(result);

		}, true);
	},

	 /**
	 * @function main.scanAnyQrCode
	 * Scan QR Code of webmaster and start alert only
	 */
	scanAnyQrCode: function() {
		devices.qrCode.scan(function(result) {
			alert(result);
		});
	},

	 /**
	 * @function main.getMac
	 * Download data of device mac and recall with this mac an alert
	 */
	getMac: function() {
		devices.mac.get(function(result) {
			alert(result);
		});
	},

	 /**
	 * @function main.getRooms
	 * Download data of rooms
	 */
	getRooms: function() {
		connection.action.getRooms(function(received) {
			// received zawiera listę elementów, np. {id: 0, name: 'room', folderName: 'room'}
			// instersuje nas id po którym dołączamy i name które wyświetlamy
			if (received.length > 0) {
				main.choseRoomToEnter(received[0].id);
			}
			storage.showRooms(received);

		});
	},

	/**
	 * @function main.initUrl
	 * Initialize url
	 */
	initUrl: function() {
		load('connecting');
		connection.initUrl(function() {
			connection.action.home(function(data) {
				if (data.id) {
					historyObj.addTohistoryObj('login');
					load('rooms', true);
				} else {
					load('login');
				}
			});
        }, function() {
            load('connection');
        });
	},

	 /**
	 * @function main.initSocket
	 * Initialize socket
	 */
	initSocket: function() {
		load('wall');
        connection.socket.init(function() {
        	connection.state = connection.states.established;
        }, function() {
            load('rooms');
        });
        connection.socket.ping();
	},

	 /**
	 * @function main.setUrl
	 * Set url to login
	 * @param {String} link
	 * link to login
	 */
	setUrl: function(link) {
        load('connecting');
		var url = document.getElementById('url');
		url.value = link;
		connection.setUrl(link, function() {
			url.value = link;

			load('login');
		}, function() {
			alert('Connection failed');
            load('connection');
		});
	},

	 /**
	 * @function main.login
	 * Login to system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 */
	login: function(login, password) {
		connection.action.login(login, password, function(received) {
			if (received.name === login) {//when everything is correct
				me.id = received.id;
				load('rooms', true);
			}
		}, function(data) { //in case of wrong input data
			alert('Wrong username or password');
		});
	},

	 /**
	 * @function main.login
	 * Register in system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 * @param {String} password2
	 * user password (confirmation)
	 */
	register: function(login, password, password2) {
		connection.action.register(login, password, password2, function(received) {
			if (received) {//when everything is correct
				load('login');
			}
		}, function(data) {//in case of wrong input data or data already exist in database
			if (data) {
				alert(data);
			} else {
				alert('Login already registered');
			}
		});
	},

	/**
	 * @function main.createRoom
	 * Create room
	 * @param {String} roomName
	 * Name of the room which user want to createElement
	 */
	createRoom: function(roomName) {
		main.choseRoomToEnter();
		connection.action.createRoom(roomName, function(received) {
			var roomId = received.id;
			main.joinRoom(received, function(answer) {
				if (answer) {
					alert('Room created');
				} else {
					alert('Creating room failed');
				}
			});
		});
	},

	/**
	 * @function main.joinRoom
	 * Join and enter to current room
	 * @param {int} roomId
	 * ID of current room
	 * @param {} callb
	 */
	joinRoom: function(roomId, callb) {
		if (roomId) {
			connection.action.joinRoom(roomId.id, function(received) {
				if (received) {
					storage.addCreatedRoom(roomId);
					//main.choseRoomToEnter(roomId);
				}
				if (callb) {
					callb(received);
				}
			});
		}
	},

	/**
	 * @function main.choseRoomToEnter
	 * Set room to which one user want to join
	 * @param {int} choseRoomToEnter
	 * User chosen room
	 */
	choseRoomToEnter: function(chosedRoomToEnter) {
		me.chosedRoomToEnter = chosedRoomToEnter;
	},

	/**
	 * @function main.goToWall
	 * Move to wall view
	 */
	goToWall: function() {
		if (me.chosedRoomToEnter) {
			window.localStorage.setItem('chosedRoomToEnter', me.chosedRoomToEnter);
			load('wall');
		} else {
			alert('No room is chosen');
		}
	},

	/**
	 * @function main.goToOnlineUsers
	 * Present list of online users
	 */
	goToOnlineUsers: function() {
		load('users', true);
	},

	 /**
	 * @function main.enterRoom
	 * Inform the server that user enter to already joined room
	 */
	enterRoom: function() {
		var roomId = window.localStorage.getItem('chosedRoomToEnter');
		if (roomId) {
			me.chosedRoomToEnter = roomId;
			connection.socket.enterRoom(roomId);
		} else {
			alert('No room is chosen');
		}
	},

	 /**
	 * @function main.scanRoomQrCode
	 * Scan QR code to current room and join this room
	 */
	scanRoomQrCode: function() {
		// scan
		devices.qrCode.scan(function(roomId) {
			// join
			main.joinRoom(roomId, function() {
				main.goToWall();
			});
		});
	},

	 /**
	 * @function main.getRoomData
	 * Download all of current room data
	 */
	getRoomData: function() {
		connection.action.getRoomData(function(data) {
			alert('getRoomData' + JSON.stringify(data));
			storage.addAllRoomData(data);
		});
	}
};

	 /**
	 * @function routing.registerAction
	 * Get rooms
	 * Get room data (wall)
	 * Present wall data
	 */
routing.registerAction('rooms', function() {
	main.getRooms();
});
routing.registerAction('wall', function() {
	connection.socket.getConnectedUsers();
	main.getRoomData();

    load('wallContent', true);
});
routing.registerAction('wallContent', function() {
	//storage.* - action of setting view after changing view
	// to set it again
});
routing.registerAction('users', function() {
	storage.showOnlineUsers();
});

	 /**
	 * @function connection.socket.receive.onEnterRoom
	 * Get data while user entered the current room
	 * @param {int, String} data
	 * Data consists of meetingID and name
	 */
connection.socket.receive.onEnterRoom = function(data) {
	me.enteredRoom = data;
	load('wall', true);
};

	 /**
	 * @function connection.socket.receive.onPing
	 * Get data while user Ping
	 */
connection.socket.receive.onPing = function() {
    main.enterRoom();
};

/**
 * Elements received from websocket is supported by functions below:
 */
 	 /**
	 * @function connection.socket.receive.onUsersOnline
	 * Add new user to OnlineUsers
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onUsersOnline = function(data) {
	alert('onUsersOnline ' + JSON.stringify(data));
	storage.getAllOnlineUsers(data);
	// add new users
};

 	 /**
	 * @function connection.socket.receive.onNewUser
	 * Alert about new user online
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onNewUser = function(data) {
	alert('onNewUser ' + JSON.stringify(data));
	storage.addNewUser(data);
	// add new user
};

 	 /**
	 * @function connection.socket.receive.onRemoveUser
	 * Delete user from OnlineUsers list
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onRemoveUser = function(data) {
	alert('onRemoveUser ' + JSON.stringify(data));
	storage.deleteUser(data);
	// remove user
};

 	 /**
	 * @function connection.socket.receive.onNewPhoto
	 * Alert about new photo
	 * @param {} data
	 * Data which contain information about photo
	 */
connection.socket.receive.onNewPhoto = function(data) {
	alert('onNewPhoto: ' + JSON.stringify(data));
    storage.addNewData(data);
};

 	 /**
	 * @function connection.socket.receive.onNewNote
	 * Alert about new note
	 * @param {} data
	 * Data which contain information about note
	 */
connection.socket.receive.onNewNote = function(data) {
	alert('onNewNote: ' + JSON.stringify(data));
    storage.addNewData(data);
};

 	 /**
	 * @function connection.socket.receive.onNewComment
	 * Alert about new comment
	 * @param {} data
	 * Data which contain information about comment
	 */
connection.socket.receive.onNewComment = function(data) {
	alert('onNewComment: ' + JSON.stringify(data));
	storage.addNewData(data);
    // add new comment
};
<commit_msg>client: przygorowanie pod lokalne pamiętanie loginu i hasła<commit_after>var me = {
	id: undefined,
	chosedRoomToEnter: undefined,
	enteredRoom: undefined
};

/**
 * Function from which we demand respond, recall,
 * giving them as parameters functions which need to be recalled
 * after receiving expected data.
 */
var main = {
	/**
	 * @function main.takePicture
	 * Take picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	takePicture: function(quality) {
		devices.camera.takePicture(quality, function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			//main.addNewMyData('image', imageSrc);
			//var image = document.getElementById('myImageCamera');
			//image.style.display = 'block';

			//image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	/**
	 * @function main.loadPicture
	 * Load picture then send it to the server and present on a wall
	 * @param {Number} quality
	 * Quality of photos is in range [1, 100].
	 */
	loadPicture: function() {
		devices.photoLibrary.take(function(imageSrc) {
			connection.file.upload.photo(imageSrc);

			var image = document.getElementById('myImageCamera');
			image.style.display = 'block';

			image.src = imageSrc/*"data:image/jpeg;base64," + */;
		});
	},

	 /**
	 * @function main.initialQrCode
	 * Scan QR Code of webmaster, get connection of websocket and save scaned data to input
	 */
	initialQrCode: function() {
		devices.qrCode.scan(function(result) {

			main.setUrl(result);

		}, true);
	},

	 /**
	 * @function main.scanAnyQrCode
	 * Scan QR Code of webmaster and start alert only
	 */
	scanAnyQrCode: function() {
		devices.qrCode.scan(function(result) {
			alert(result);
		});
	},

	 /**
	 * @function main.getMac
	 * Download data of device mac and recall with this mac an alert
	 */
	getMac: function() {
		devices.mac.get(function(result) {
			alert(result);
		});
	},

	 /**
	 * @function main.getRooms
	 * Download data of rooms
	 */
	getRooms: function() {
		connection.action.getRooms(function(received) {
			// received zawiera listę elementów, np. {id: 0, name: 'room', folderName: 'room'}
			// instersuje nas id po którym dołączamy i name które wyświetlamy
			if (received.length > 0) {
				main.choseRoomToEnter(received[0].id);
			}
			storage.showRooms(received);

		});
	},

	/**
	 * @function main.initUrl
	 * Initialize url
	 */
	initUrl: function() {
		load('connecting');
		connection.initUrl(function() {
			connection.action.home(function(data) {
				if (data.id) {
					historyObj.addTohistoryObj('login');
					load('rooms', true);
				} else {
					load('login', true);
				}
			});
        }, function() {
            load('connection');
        });
	},

	 /**
	 * @function main.initSocket
	 * Initialize socket
	 */
	initSocket: function() {
		load('wall');
        connection.socket.init(function() {
        	connection.state = connection.states.established;
        }, function() {
            load('rooms');
        });
        connection.socket.ping();
	},

	 /**
	 * @function main.setUrl
	 * Set url to login
	 * @param {String} link
	 * link to login
	 */
	setUrl: function(link) {
        load('connecting');
		var url = document.getElementById('url');
		url.value = link;
		connection.setUrl(link, function() {
			url.value = link;

			load('login', true);
		}, function() {
			alert('Connection failed');
            load('connection');
		});
	},

	 /**
	 * @function main.login
	 * Login to system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 */
	login: function(login, password) {
		connection.action.login(login, password, function(received) {
			if (received.name === login) {//when everything is correct
				me.id = received.id;
				storage.setUserLogin(login);
				storage.setUserPassword(password);
				load('rooms', true);
			}
		}, function(data) { //in case of wrong input data
			alert('Wrong username or password');
		});
	},

	 /**
	 * @function main.login
	 * Register in system
	 * @param {String} login
	 * user login
	 * @param {String} password
	 * user password
	 * @param {String} password2
	 * user password (confirmation)
	 */
	register: function(login, password, password2) {
		connection.action.register(login, password, password2, function(received) {
			if (received) {//when everything is correct
				load('login', true);
			}
		}, function(data) {//in case of wrong input data or data already exist in database
			if (data) {
				alert(data);
			} else {
				alert('Login already registered');
			}
		});
	},

	/**
	 * @function main.createRoom
	 * Create room
	 * @param {String} roomName
	 * Name of the room which user want to createElement
	 */
	createRoom: function(roomName) {
		main.choseRoomToEnter();
		connection.action.createRoom(roomName, function(received) {
			var roomId = received.id;
			main.joinRoom(received, function(answer) {
				if (answer) {
					alert('Room created');
				} else {
					alert('Creating room failed');
				}
			});
		});
	},

	/**
	 * @function main.joinRoom
	 * Join and enter to current room
	 * @param {int} roomId
	 * ID of current room
	 * @param {} callb
	 */
	joinRoom: function(roomId, callb) {
		if (roomId) {
			connection.action.joinRoom(roomId.id, function(received) {
				if (received) {
					storage.addCreatedRoom(roomId);
					//main.choseRoomToEnter(roomId);
				}
				if (callb) {
					callb(received);
				}
			});
		}
	},

	/**
	 * @function main.choseRoomToEnter
	 * Set room to which one user want to join
	 * @param {int} choseRoomToEnter
	 * User chosen room
	 */
	choseRoomToEnter: function(chosedRoomToEnter) {
		me.chosedRoomToEnter = chosedRoomToEnter;
	},

	/**
	 * @function main.goToWall
	 * Move to wall view
	 */
	goToWall: function() {
		if (me.chosedRoomToEnter) {
			window.localStorage.setItem('chosedRoomToEnter', me.chosedRoomToEnter);
			load('wall');
		} else {
			alert('No room is chosen');
		}
	},

	/**
	 * @function main.goToOnlineUsers
	 * Present list of online users
	 */
	goToOnlineUsers: function() {
		load('users', true);
	},

	 /**
	 * @function main.enterRoom
	 * Inform the server that user enter to already joined room
	 */
	enterRoom: function() {
		var roomId = window.localStorage.getItem('chosedRoomToEnter');
		if (roomId) {
			me.chosedRoomToEnter = roomId;
			connection.socket.enterRoom(roomId);
		} else {
			alert('No room is chosen');
		}
	},

	 /**
	 * @function main.scanRoomQrCode
	 * Scan QR code to current room and join this room
	 */
	scanRoomQrCode: function() {
		// scan
		devices.qrCode.scan(function(roomId) {
			// join
			main.joinRoom(roomId, function() {
				main.goToWall();
			});
		});
	},

	 /**
	 * @function main.getRoomData
	 * Download all of current room data
	 */
	getRoomData: function() {
		connection.action.getRoomData(function(data) {
			alert('getRoomData' + JSON.stringify(data));
			storage.addAllRoomData(data);
		});
	}
};

	 /**
	 * @function routing.registerAction
	 * Get rooms
	 * Get room data (wall)
	 * Present wall data
	 */
routing.registerAction('rooms', function() {
	main.getRooms();
});
routing.registerAction('wall', function() {
	connection.socket.getConnectedUsers();
	main.getRoomData();

    load('wallContent', true);
});
routing.registerAction('wallContent', function() {
	//storage.* - action of setting view after changing view
	// to set it again
});
routing.registerAction('users', function() {
	storage.showOnlineUsers();
});
routing.registerAction('login', function() {
	//storage.initLoginData
});

	 /**
	 * @function connection.socket.receive.onEnterRoom
	 * Get data while user entered the current room
	 * @param {int, String} data
	 * Data consists of meetingID and name
	 */
connection.socket.receive.onEnterRoom = function(data) {
	me.enteredRoom = data;
	load('wall', true);
};

	 /**
	 * @function connection.socket.receive.onPing
	 * Get data while user Ping
	 */
connection.socket.receive.onPing = function() {
    main.enterRoom();
};

/**
 * Elements received from websocket is supported by functions below:
 */
 	 /**
	 * @function connection.socket.receive.onUsersOnline
	 * Add new user to OnlineUsers
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onUsersOnline = function(data) {
	alert('onUsersOnline ' + JSON.stringify(data));
	storage.getAllOnlineUsers(data);
	// add new users
};

 	 /**
	 * @function connection.socket.receive.onNewUser
	 * Alert about new user online
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onNewUser = function(data) {
	alert('onNewUser ' + JSON.stringify(data));
	storage.addNewUser(data);
	// add new user
};

 	 /**
	 * @function connection.socket.receive.onRemoveUser
	 * Delete user from OnlineUsers list
	 * @param {} data
	 * Data which contain user data
	 */
connection.socket.receive.onRemoveUser = function(data) {
	alert('onRemoveUser ' + JSON.stringify(data));
	storage.deleteUser(data);
	// remove user
};

 	 /**
	 * @function connection.socket.receive.onNewPhoto
	 * Alert about new photo
	 * @param {} data
	 * Data which contain information about photo
	 */
connection.socket.receive.onNewPhoto = function(data) {
	alert('onNewPhoto: ' + JSON.stringify(data));
    storage.addNewData(data);
};

 	 /**
	 * @function connection.socket.receive.onNewNote
	 * Alert about new note
	 * @param {} data
	 * Data which contain information about note
	 */
connection.socket.receive.onNewNote = function(data) {
	alert('onNewNote: ' + JSON.stringify(data));
    storage.addNewData(data);
};

 	 /**
	 * @function connection.socket.receive.onNewComment
	 * Alert about new comment
	 * @param {} data
	 * Data which contain information about comment
	 */
connection.socket.receive.onNewComment = function(data) {
	alert('onNewComment: ' + JSON.stringify(data));
	storage.addNewData(data);
    // add new comment
};
<|endoftext|>


<commit_before>import React, { PropTypes } from 'react'
import Widget from './widget.connected'
import BlockConfigMenu from './block-config-menu.connected'
import { EDIT_KEY } from './block-config-menu'
import BlockChangeBackground from './block-change-background.connected'

export const HOVER_MOUSE_KEY = 'block'

const Block = ({ block, widgets, editable, hasMouseOver, onMouseOver, onMouseOut, onCancelEdit, editing, saving }) => (
  <div
    id={`block-${block.id}`}
    onMouseOver={() => onMouseOver(HOVER_MOUSE_KEY, block.id)}
    onMouseOut={() => onMouseOut(HOVER_MOUSE_KEY)}
    onKeyUp={evt => {
      // ESC keycode
      if (evt.keyCode === 27) {
        onCancelEdit(block)
      }
    }}
  >

      {editing === EDIT_KEY ? <BlockChangeBackground block={block} /> : null}

        {widgets && widgets.map(widget => (
          <Widget widget={widget} editable={editable} />
        ))}

      {block.hidden && (

             Escondido

      )}

        <BlockConfigMenu
          block={block}
          display={editable && hasMouseOver && !editing && !saving ? true : false}
        />

)

Block.propTypes = {
  block: PropTypes.object.isRequired,
  widgets: PropTypes.array.isRequired,
  editable: PropTypes.bool,
  // Injected by redux
  hasMouseOver: PropTypes.bool,
  onMouseOver: PropTypes.func,
  onMouseOut: PropTypes.func,
  onCancelEdit: PropTypes.func,
  editing: PropTypes.string,
  saving: PropTypes.bool
}

export default Block
<commit_msg>Change mouse over/out for enter/leave<commit_after>import React, { PropTypes } from 'react'
import Widget from './widget.connected'
import BlockConfigMenu from './block-config-menu.connected'
import { EDIT_KEY } from './block-config-menu'
import BlockChangeBackground from './block-change-background.connected'

export const HOVER_MOUSE_KEY = 'block'

const Block = ({ block, widgets, editable, hasMouseOver, onMouseOver, onMouseOut, onCancelEdit, editing, saving }) => (
  <div
    id={`block-${block.id}`}
    onMouseEnter={() => onMouseOver(HOVER_MOUSE_KEY, block.id)}
    onMouseLeave={() => onMouseOut(HOVER_MOUSE_KEY)}
    onKeyUp={evt => {
      // ESC keycode
      if (evt.keyCode === 27) {
        onCancelEdit(block)
      }
    }}
  >

      {editing === EDIT_KEY ? <BlockChangeBackground block={block} /> : null}

        {widgets && widgets.map(widget => (
          <Widget widget={widget} editable={editable} />
        ))}

      {block.hidden && (

             Escondido

      )}

        <BlockConfigMenu
          block={block}
          display={editable && hasMouseOver && !editing && !saving ? true : false}
        />

)

Block.propTypes = {
  block: PropTypes.object.isRequired,
  widgets: PropTypes.array.isRequired,
  editable: PropTypes.bool,
  // Injected by redux
  hasMouseOver: PropTypes.bool,
  onMouseOver: PropTypes.func,
  onMouseOut: PropTypes.func,
  onCancelEdit: PropTypes.func,
  editing: PropTypes.string,
  saving: PropTypes.bool
}

export default Block
<|endoftext|>


<commit_before>import React from 'react';
import {View, Button, StyleSheet} from 'react-native';
import {connect} from 'react-redux';
import {reduxForm, Field} from 'redux-form';
import {FieldWrapper} from './simple/FieldWrapper';
import TextInputField from './simple/TextInputField';
import axios from 'axios';
import {saveToken} from '../reducers/authentication';
import {setBackendUrl} from '../reducers/backend';
import {colors} from '../constants/colors';

@connect(state =>
  ({
    initialValues: {
      backend: state.backend
    }
  })
)
@reduxForm({form: 'login', enableReinitialize: true})
export class LoginScreen extends React.Component {

  static propTypes = {
    dispatch: React.PropTypes.func.isRequired,
    handleSubmit: React.PropTypes.func.isRequired
  };

  onSubmit = (data) => {
    this.performLogin(data.backend, data.email, data.password);
    this.props.dispatch(setBackendUrl(data.backend));
  };

  performLogin = (backend, email, password) => {
    axios({
      url: `${backend}/login`,
      method: 'POST',
      data: {
        email,
        password
      }
    }).then(response => {
      if (response.headers.authorization) {
        // Dispatch save token
        this.props.dispatch(saveToken(response.headers.authorization));
      } else {
        alert('Login error');
      }
    }).catch(err => alert('Login error: ' + err.toString()));
  };

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.loginView}>
          <FieldWrapper>
            <Field
              name="backend"
              component={TextInputField}
              placeholder="Backend"
            />
          </FieldWrapper>

          <FieldWrapper>
            <Field
              name="email"
              component={TextInputField}
              placeholder="Email"
            />
          </FieldWrapper>

          <FieldWrapper>
            <Field
              name="password"
              component={TextInputField}
              placeholder="Password"
              secureTextEntry
            />
          </FieldWrapper>

          <Button
            onPress={this.props.handleSubmit(this.onSubmit)}
            title="Login"
          />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: colors.headerColor,
  },
  loginView: {
    paddingVertical: 20,

    backgroundColor: '#fafafa',
    borderColor: '#e5e5e5',
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderTopWidth: StyleSheet.hairlineWidth
  }
});
<commit_msg>Better keyboard behaviour for the login screen<commit_after>import React from 'react';
import {View, Button, StyleSheet} from 'react-native';
import {connect} from 'react-redux';
import {reduxForm, Field} from 'redux-form';
import {FieldWrapper} from './simple/FieldWrapper';
import TextInputField from './simple/TextInputField';
import axios from 'axios';
import {saveToken} from '../reducers/authentication';
import {setBackendUrl} from '../reducers/backend';
import {colors} from '../constants/colors';

@connect(state =>
  ({
    initialValues: {
      backend: state.backend
    }
  })
)
@reduxForm({form: 'login', enableReinitialize: true})
export class LoginScreen extends React.Component {

  static propTypes = {
    dispatch: React.PropTypes.func.isRequired,
    handleSubmit: React.PropTypes.func.isRequired
  };

  onSubmit = (data) => {
    this.performLogin(data.backend, data.email, data.password);
    this.props.dispatch(setBackendUrl(data.backend));
  };

  performLogin = (backend, email, password) => {
    axios({
      url: `${backend}/login`,
      method: 'POST',
      data: {
        email,
        password
      }
    }).then(response => {
      if (response.headers.authorization) {
        // Dispatch save token
        this.props.dispatch(saveToken(response.headers.authorization));
      } else {
        alert('Login error');
      }
    }).catch(err => alert('Login error: ' + err.toString()));
  };

  render() {
    return (
      <View style={styles.container}>
        <View style={styles.loginView}>
          <FieldWrapper>
            <Field
              name="backend"
              component={TextInputField}
              placeholder="Backend"
              autoCapitalize="none"
            />
          </FieldWrapper>

          <FieldWrapper>
            <Field
              name="email"
              component={TextInputField}
              placeholder="Email"
              autoCapitalize="none"
              keyboardType="email-address"
            />
          </FieldWrapper>

          <FieldWrapper>
            <Field
              name="password"
              component={TextInputField}
              placeholder="Password"
              secureTextEntry
            />
          </FieldWrapper>

          <Button
            onPress={this.props.handleSubmit(this.onSubmit)}
            title="Login"
          />
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: 'center',
    backgroundColor: colors.headerColor,
  },
  loginView: {
    paddingVertical: 20,

    backgroundColor: '#fafafa',
    borderColor: '#e5e5e5',
    borderBottomWidth: StyleSheet.hairlineWidth,
    borderTopWidth: StyleSheet.hairlineWidth
  }
});
<|endoftext|>


<commit_before>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import SelectedProjectView from '../containers/SelectedProjectView';

class ProjectView extends Component {
  connectToProject() {
    console.log('Joining...');
    this.props.socket.emit('userReady', this.props.project.projectId);
  }

  disconnectFromProject() {
    console.log(`Disconnecting from project: ${this.props.project['title']}`);
    this.props.socket.emit('userDisconnect');
    // TODO: terminate the existing worker
  }

  render() {
    console.log(this.props.project);
    console.log(this.props.project['title']);

    return (

        <SelectedProjectView />
        This is the project view.

        <button onClick={this.connectToProject.bind(this)}>Join</button>
        <button onClick={this.disconnectFromProject.bind(this)}>Leave</button>

    )
  }
}

function mapStateToProps(state) {
  return {
    project: state.selectedProject,
    socket: state.createdSocket
  }
}

export default connect(mapStateToProps)(ProjectView);<commit_msg>ProjectView displays results<commit_after>import React, { Component } from 'react';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';
import SelectedProjectView from '../containers/SelectedProjectView';

class ProjectView extends Component {
  connectToProject() {
    console.log('Joining...');
    this.props.socket.emit('userReady', this.props.project.projectId);
  }

  disconnectFromProject() {
    console.log(`Disconnecting from project: ${this.props.project['title']}`);
    this.props.socket.emit('userDisconnect');
    // TODO: terminate the existing worker
  }

  render() {
    console.log(this.props.results);

    return (

        <SelectedProjectView />
        This is the project view.

        <button onClick={this.connectToProject.bind(this)}>Join</button>
        <button onClick={this.disconnectFromProject.bind(this)}>Leave</button>

          Number of results so far: {this.props.results === null ? 'zero' : this.props.results.length}

    )
  }
}

function mapStateToProps(state) {
  return {
    project: state.selectedProject,
    socket: state.createdSocket,
    results: state.updateResults
  }
}

export default connect(mapStateToProps)(ProjectView);<|endoftext|>


<commit_before>DataBind = (function () {

    var listenersHash = {};
    var KEY_PROP = 'data-key';

    function changeHandler(ev) {
        console.log('#' + this.id + ' ev:' + ev.type + ' new val:' + value(this));
    }

    function value(el, newVal) {
        if (!el) return undefined;
        var isSetter = (newVal !== undefined);
        if (['checkbox', 'radio'].indexOf(el.type) >= 0) {
            if (isSetter) {
                el.checked = !!newVal;
            }
            return el.checked;
        }
        if (['text', 'textarea', 'select-one'].indexOf(el.type) >= 0) {
            if (isSetter) {
                el.value = newVal;
            }
            return el.value;
        }

        if (['select-multiple'].indexOf(el.type) >= 0) {
            if (isSetter) {
                if (!isArray(newVal)) {
                    newVal = [newVal];
                }
            }
            var result = [];
            var options = el && el.options;
            var opt;

            for (var i = 0, iLen = options.length; i < iLen; i++) {
                opt = options[i];

                if (isSetter) {
                    if (newVal.indexOf(opt.value) > -1) {
                        opt.selected = true;
                    } else {
                        opt.selected = false;
                    }
                }

                if (opt.selected) {
                    result.push(opt.value || opt.text);
                }
            }
            return result;
        }

        // else assume non-input element
        if (isSetter) {
            el.innerText = newVal;
        }
        return el.innerText;
    }

    function isArray(val) {
        return ( Object.prototype.toString.call(val) === '[object Array]' );
    }

    function addListener(el, ev, fn) {
        if (!el || !ev || !fn) return;
        return el.addEventListener(ev, fn, false);
    }

    function removeListener(el, ev, fn) {

    }

    function getEventNameForEl(el) {
        if (['checkbox', 'radio', 'select-one', 'select-multiple'].indexOf(el.type) >= 0) {
            return 'change';
        }
        if (['text', 'textarea'].indexOf(el.type) >= 0) {
            return 'input';
        }
    }

    function getOrGenElHashkey(el) {
        if (!el.hashkey) {
            el.hashkey = Date.now() + Math.floor(Math.random() * 100000);
        }

        return el.hashkey;
    }

    function listen(el, fn) {
        if (!el || !fn) return;

        var hashkey = getOrGenElHashkey(el);
        // save the listener in listeners has for later removal
        listenersHash[hashkey] = listenersHash[hashkey] || [];
        // prevent double listening on same fn on same obj
        if (listenersHash[hashkey].indexOf(fn) > -1) return;
        // we're safe to add this handler
        listenersHash[hashkey].push(fn);

        var evName = getEventNameForEl(el);
        el.addEventListener(evName, fn, false);
    }

    function unlistenOne(el, fn) {
        // check if this fn was ever listened to
        var hashkey = getOrGenElHashkey(el);
        var idx = listenersHash[hashkey].indexOf(fn);
        if (!listenersHash[hashkey] || idx === -1) return;
        // remove fn from the hash
        listenersHash[hashkey].splice(idx, 1);

        var evName = getEventNameForEl(el);
        el.removeEventListener(evName, fn, false);
    }

    function unlisten(el, fn) {
        var hashkey = getOrGenElHashkey(el);
        var listeners = listenersHash[hashkey];
        if (!el || !listeners) return;
        if (fn) {
            return unlistenOne(el, fn);
        }
        // no fn provided - remove all
        var listenersClone = listeners.concat();
        var i, len = listenersClone.length;
        for (i = 0; i < len; i++) {
            unlistenOne(el, listenersClone[i]);
        }
    }

    function keyExists(model, key) {
        var splitKey = key.split('.');
        var modelDepth = model;
        var i;

        for (i = 0; i < splitKey.length; i++) {
            if (!modelDepth.hasOwnProperty(splitKey[i])) return false;
            modelDepth = modelDepth[ splitKey[i] ];
        }
        return true;
    }

    function getModelDeepKey(model, key) {
        var splitKey = key.split('.');
        var modelDepth = model;
        var i;

        for (i = 0; i < splitKey.length - 1; i++) {
            modelDepth = modelDepth[ splitKey[i] ];
        }
        return modelDepth;
    }

    function modelValue(model, key, newVal) {
        var splitKey = key.split('.');
        var deepModel = getModelDeepKey(model, key);
        if (newVal !== undefined) {
            deepModel[splitKey[ splitKey.length - 1 ]] = newVal;
        }
        return deepModel[splitKey[ splitKey.length - 1 ]];
    }

    function bindDom(el, deepModel, deepKey) {
        // listen to elem changes -> on change set model with new value
        var fn = (function (el, deepModel, deepKey, modelValueFn, valueFn) {
            return function (ev) {
                var newVal = valueFn(this);
                modelValueFn(deepModel, deepKey, newVal);
            };
        })(el, deepModel, deepKey, modelValue, value);
        listen(el, fn);
        // listen again, just to print it out
        // TODO remove this debug calls
        listen(el, changeHandler);
    }

    function unbindDom(el) {
        unlisten(el);
    }

    function bindModel(el, deepModel, deepKey) {
        // watch model's key -> on change set el's new value
        var fn = (function (el, deepModel, deepKey, valueFn) {
            return function (key, setOrGet, newVal, oldVal) {
                valueFn(el, newVal);
            }
        })(el, deepModel, deepKey, value);
        WatchJS.watch(deepModel, deepKey, fn);
    }

    function unbindModel(deepModel, deepKey) {
        // TODO not use internal impl of watch.js - deepModel.watchers[deepKey]
        var watchers = deepModel.watchers[deepKey];
        var i;
        for (i = 0; i < watchers.length; i++) {
            WatchJS.unwatch(deepModel, deepKey, watchers[i]);
        }

    }

    function getDatasetKey(el) {
        if (!el) return;
        return el.getAttribute(KEY_PROP);
    }

    function bindSingleEl(el, model, cfg) {
        if (!el || !model) return;

        // TODO extract this section somehow
        // extract model's key to watch from el's data-key
        var key = getDatasetKey(el);
        // make sure the key is defined in the model
        if (!keyExists(model, key)) return;
        var deepModel = getModelDeepKey(model, key);
        var deepKey = key.split('.');
        deepKey = deepKey[ deepKey.length - 1 ];

        // update elem from model
        var modelVal = modelValue(model, key);
        value(el, modelVal);

        if (cfg.dom) {
            bindDom(el, deepModel, deepKey);
        }

        if (cfg.model) {
            bindModel(el, deepModel, deepKey);
        }
    }

    function getBindUnbindConfigDefaults(cfg) {
        cfg = cfg || {};
        cfg = {
            dom: (cfg.dom !== undefined) ? cfg.dom : true,
            model: (cfg.model !== undefined) ? cfg.model : true,
            children: (cfg.children !== undefined) ? cfg.children : true
        };
        return cfg;
    }

    function bind(el, model, cfg) {
        if (!el || !model) return;
        cfg = getBindUnbindConfigDefaults(cfg);
        // TODO if cfg.children traverse el's tree and bind all children that have the key
        bindSingleEl(el, model, {
            dom: cfg.dom,
            model: cfg.model
        });
    }

    function unbindSingleEl(el, model, cfg) {
        if (!el || !model) return;
        // TODO extract this section somehow
        // extract model's key to watch from el's data-key
        var key = getDatasetKey(el);
        // make sure the key is defined in the model
        if (!keyExists(model, key)) return;
        var deepModel = getModelDeepKey(model, key);
        var deepKey = key.split('.');
        deepKey = deepKey[ deepKey.length - 1 ];
        if (cfg.dom) {
            unbindDom(el);
        }

        if (cfg.model) {
            unbindModel(deepModel, deepKey);
        }
    }

    function unbind(el, model, cfg) {
        if (!el || !model) return;
        cfg = getBindUnbindConfigDefaults(cfg);
        // TODO if cfg.children traverse el's tree and unbind all children that have the key
        unbindSingleEl(el, model, {
            dom: cfg.dom,
            model: cfg.model
        });

    }

    return {
        bind: bind,
        unbind: unbind
    };
})();
<commit_msg>better code reuse<commit_after>DataBind = (function () {

    var listenersHash = {};
    var KEY_PROP = 'data-key';

    function changeHandler(ev) {
        console.log('#' + this.id + ' ev:' + ev.type + ' new val:' + value(this));
    }

    function value(el, newVal) {
        if (!el) return undefined;
        var isSetter = (newVal !== undefined);
        if (['checkbox', 'radio'].indexOf(el.type) >= 0) {
            if (isSetter) {
                el.checked = !!newVal;
            }
            return el.checked;
        }
        if (['text', 'textarea', 'select-one'].indexOf(el.type) >= 0) {
            if (isSetter) {
                el.value = newVal;
            }
            return el.value;
        }

        if (['select-multiple'].indexOf(el.type) >= 0) {
            if (isSetter) {
                if (!isArray(newVal)) {
                    newVal = [newVal];
                }
            }
            var result = [];
            var options = el && el.options;
            var opt;

            for (var i = 0, iLen = options.length; i < iLen; i++) {
                opt = options[i];

                if (isSetter) {
                    if (newVal.indexOf(opt.value) > -1) {
                        opt.selected = true;
                    } else {
                        opt.selected = false;
                    }
                }

                if (opt.selected) {
                    result.push(opt.value || opt.text);
                }
            }
            return result;
        }

        // else assume non-input element
        if (isSetter) {
            el.innerText = newVal;
        }
        return el.innerText;
    }

    function isArray(val) {
        return ( Object.prototype.toString.call(val) === '[object Array]' );
    }

    function addListener(el, ev, fn) {
        if (!el || !ev || !fn) return;
        return el.addEventListener(ev, fn, false);
    }

    function removeListener(el, ev, fn) {

    }

    function getEventNameForEl(el) {
        if (['checkbox', 'radio', 'select-one', 'select-multiple'].indexOf(el.type) >= 0) {
            return 'change';
        }
        if (['text', 'textarea'].indexOf(el.type) >= 0) {
            return 'input';
        }
    }

    function getOrGenElHashkey(el) {
        if (!el.hashkey) {
            el.hashkey = Date.now() + Math.floor(Math.random() * 100000);
        }

        return el.hashkey;
    }

    function listen(el, fn) {
        if (!el || !fn) return;

        var hashkey = getOrGenElHashkey(el);
        // save the listener in listeners has for later removal
        listenersHash[hashkey] = listenersHash[hashkey] || [];
        // prevent double listening on same fn on same obj
        if (listenersHash[hashkey].indexOf(fn) > -1) return;
        // we're safe to add this handler
        listenersHash[hashkey].push(fn);

        var evName = getEventNameForEl(el);
        el.addEventListener(evName, fn, false);
    }

    function unlistenOne(el, fn) {
        // check if this fn was ever listened to
        var hashkey = getOrGenElHashkey(el);
        var idx = listenersHash[hashkey].indexOf(fn);
        if (!listenersHash[hashkey] || idx === -1) return;
        // remove fn from the hash
        listenersHash[hashkey].splice(idx, 1);

        var evName = getEventNameForEl(el);
        el.removeEventListener(evName, fn, false);
    }

    function unlisten(el, fn) {
        var hashkey = getOrGenElHashkey(el);
        var listeners = listenersHash[hashkey];
        if (!el || !listeners) return;
        if (fn) {
            return unlistenOne(el, fn);
        }
        // no fn provided - remove all
        var listenersClone = listeners.concat();
        var i, len = listenersClone.length;
        for (i = 0; i < len; i++) {
            unlistenOne(el, listenersClone[i]);
        }
    }

    function keyExists(model, key) {
        var splitKey = key.split('.');
        var modelDepth = model;
        var i;

        for (i = 0; i < splitKey.length; i++) {
            if (!modelDepth.hasOwnProperty(splitKey[i])) return false;
            modelDepth = modelDepth[ splitKey[i] ];
        }
        return true;
    }

    function getModelDeepKey(model, key) {
        var splitKey = key.split('.');
        var modelDepth = model;
        var i;

        for (i = 0; i < splitKey.length - 1; i++) {
            modelDepth = modelDepth[ splitKey[i] ];
        }
        return modelDepth;
    }

    function modelValue(model, key, newVal) {
        var splitKey = key.split('.');
        var deepModel = getModelDeepKey(model, key);
        if (newVal !== undefined) {
            deepModel[splitKey[ splitKey.length - 1 ]] = newVal;
        }
        return deepModel[splitKey[ splitKey.length - 1 ]];
    }

    function bindDom(el, deepModel, deepKey) {
        // listen to elem changes -> on change set model with new value
        var fn = (function (el, deepModel, deepKey, modelValueFn, valueFn) {
            return function (ev) {
                var newVal = valueFn(this);
                modelValueFn(deepModel, deepKey, newVal);
            };
        })(el, deepModel, deepKey, modelValue, value);
        listen(el, fn);
        // listen again, just to print it out
        // TODO remove this debug calls
        listen(el, changeHandler);
    }

    function unbindDom(el) {
        unlisten(el);
    }

    function bindModel(el, deepModel, deepKey) {
        // watch model's key -> on change set el's new value
        var fn = (function (el, deepModel, deepKey, valueFn) {
            return function (key, setOrGet, newVal, oldVal) {
                valueFn(el, newVal);
            }
        })(el, deepModel, deepKey, value);
        WatchJS.watch(deepModel, deepKey, fn);
    }

    function unbindModel(deepModel, deepKey) {
        // TODO not use internal impl of watch.js - deepModel.watchers[deepKey]
        var watchers = deepModel.watchers[deepKey];
        var i;
        for (i = 0; i < watchers.length; i++) {
            WatchJS.unwatch(deepModel, deepKey, watchers[i]);
        }

    }

    function getDatasetKey(el) {
        if (!el) return;
        return el.getAttribute(KEY_PROP);
    }

    function bindSingleEl(el, model, cfg) {
        if (!el || !model) return;

        var props = getCommonBindingProps(el, model);
        if (!props.keyExists) return;

        // update elem from model
        var modelVal = modelValue(model, props.key);
        value(el, modelVal);

        if (cfg.dom) {
            bindDom(el, props.deepModel, props.deepKey);
        }

        if (cfg.model) {
            bindModel(el, props.deepModel, props.deepKey);
        }
    }

    function getBindUnbindConfigDefaults(cfg) {
        cfg = cfg || {};
        cfg = {
            dom: (cfg.dom !== undefined) ? cfg.dom : true,
            model: (cfg.model !== undefined) ? cfg.model : true,
            children: (cfg.children !== undefined) ? cfg.children : true
        };
        return cfg;
    }

    function bind(el, model, cfg) {
        if (!el || !model) return;
        cfg = getBindUnbindConfigDefaults(cfg);
        // TODO if cfg.children traverse el's tree and bind all children that have the key
        bindSingleEl(el, model, {
            dom: cfg.dom,
            model: cfg.model
        });
    }

    function getCommonBindingProps(el, model) {
        if (!el || !model) return {};

        // extract model's key to watch from el's data-key
        var key = getDatasetKey(el);
        // make sure the key is defined in the model
        var isKeyExists = keyExists(model, key);
        var deepModel = getModelDeepKey(model, key);
        var deepKey = key.split('.');
        deepKey = deepKey[ deepKey.length - 1 ];

        return {
            key: key,
            deepKey: deepKey,
            deepModel: deepModel,
            keyExists: isKeyExists
        }
    }

    function unbindSingleEl(el, model, cfg) {
        if (!el || !model) return;

        var props = getCommonBindingProps(el, model);
        if (!props.keyExists) return;

        if (cfg.dom) {
            unbindDom(el);
        }

        if (cfg.model) {
            unbindModel(props.deepModel, props.deepKey);
        }
    }

    function unbind(el, model, cfg) {
        if (!el || !model) return;
        cfg = getBindUnbindConfigDefaults(cfg);
        // TODO if cfg.children traverse el's tree and unbind all children that have the key
        unbindSingleEl(el, model, {
            dom: cfg.dom,
            model: cfg.model
        });

    }

    return {
        bind: bind,
        unbind: unbind
    };
})();
<|endoftext|>


<commit_before>"use strict";

import React from 'react';
import UserStore from '../stores/UserStore';
import Constants from '../constants/Constants';
import AddWeight from './AddWeight';
import FloatingActionButton from 'material-ui/lib/floating-action-button';
import Card from './common/card';

export default class UserTile extends React.Component {
    componentWillMount() {
        this.state = UserStore.getState();
    }

    // profilePic(user) {
    //     if (user) {
    //         switch (user.provider) {
    //             case 'facebook':
    //                 return `http://graph.facebook.com/${user.data.id}/picture`
    //                 break;
    //             default:
    //                 return `http://placehold.it/50x50`
    //
    //         }
    //     }
    // }
    //
    // userName(user) {
    //     if (user) {
    //         switch (user.provider) {
    //             case 'facebook':
    //                 return user.data.first_name + ' ' + user.data.last_name
    //                 break;
    //             default:
    //                 return user.username
    //
    //         }
    //     }
    // }

    render() {
        return (
            <Card cssClass="userComponent">

{this.state.user.name}

Logout

<AddWeight/>

            </Card>
        )
    }
}
<commit_msg>[client] Logout functionality<commit_after>"use strict";

import React from 'react';
import UserStore from '../stores/UserStore';
import Constants from '../constants/Constants';
import AddWeight from './AddWeight';
import FloatingActionButton from 'material-ui/lib/floating-action-button';
import Card from './common/card';

export default class UserTile extends React.Component {
    componentWillMount() {
        this.state = UserStore.getState();
    }

    // profilePic(user) {
    //     if (user) {
    //         switch (user.provider) {
    //             case 'facebook':
    //                 return `http://graph.facebook.com/${user.data.id}/picture`
    //                 break;
    //             default:
    //                 return `http://placehold.it/50x50`
    //
    //         }
    //     }
    // }
    //
    // userName(user) {
    //     if (user) {
    //         switch (user.provider) {
    //             case 'facebook':
    //                 return user.data.first_name + ' ' + user.data.last_name
    //                 break;
    //             default:
    //                 return user.username
    //
    //         }
    //     }
    // }

    handleLogout(e) {
        e.preventDefault();
        localStorage.removeItem('userToken');
        window.location.hash = '';
        window.location.href = window.location.href;
    }

    render() {
        return (
            <Card cssClass="userComponent">

{this.state.user.name}

Logout

<AddWeight/>

            </Card>
        )
    }
}
<|endoftext|>


<commit_before>/**
 * Created by Daniel on 2016-10-21.
 */
const sqlite3 = require('sqlite3').verbose()
const Database = new sqlite3.Database('Database.sqlite3').run('PRAGMA foreign_keys = ON')

class DatabaseOperation
{
    static CreateTables()
    {
        Database.serialize(function ()
        {
            Database.run('create table if not exists Tag(ID_Tag INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Value TEXT)', ErrorCallback)
            Database.run('create table if not exists BLOB(ID_BLOB INTEGER PRIMARY KEY AUTOINCREMENT, BLOB BLOB, Checksum TEXT)', ErrorCallback)
            Database.run('create table if not exists Location(ID_Location INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT, Location TEXT)', ErrorCallback)
            Database.run('create table if not exists File(ID_File INTEGER PRIMARY KEY AUTOINCREMENT, Filename TEXT, ID_BLOB INTEGER, FOREIGN KEY(ID_BLOB) REFERENCES BLOB(ID_BLOB))', ErrorCallback)
            Database.run('create table if not exists Collection(ID_Collection INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, ID_ParentCollection INTEGER, FOREIGN KEY(ID_ParentCollection) REFERENCES Collection(ID_Collection))', ErrorCallback)
            Database.run('create table if not exists File_Collection(ID_File INTEGER NOT NULL, ID_Collection INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Collection) REFERENCES Collection(ID_Collection), PRIMARY KEY(ID_File, ID_Collection))', ErrorCallback)
            Database.run('create table if not exists File_Location(ID_File INTEGER NOT NULL, ID_Location INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Location) REFERENCES Location(ID_Location), PRIMARY KEY(ID_File, ID_Location))', ErrorCallback)
            Database.run('create table if not exists File_Tag(ID_File INTEGER NOT NULL, ID_Tag INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Tag) REFERENCES Tag(ID_Tag), PRIMARY KEY(ID_File, ID_Tag))', ErrorCallback)
        })
    }

    static DropTables()
    {
        Database.serialize(function ()
        {
            Database.run('drop table if exists File_Tag', ErrorCallback)
            Database.run('drop table if exists File_Location', ErrorCallback)
            Database.run('drop table if exists File_Collection', ErrorCallback)
            Database.run('drop table if exists Collection', ErrorCallback)
            Database.run('drop table if exists File', ErrorCallback)
            Database.run('drop table if exists Location', ErrorCallback)
            Database.run('drop table if exists BLOB', ErrorCallback)
            Database.run('drop table if exists Tag', ErrorCallback)
        })
    }

    static  ShowTables()
    {
        Database.all("select name from sqlite_master where type='table'", function (err, tables)
        {
            console.log(tables)
        })
    }
}

DatabaseOperation.Tag = class Tag
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateTag(Name, Value, Callback)
    {
        Database.run('INSERT INTO Tag (Name, Value) VALUES ($Name, $Value)', {$Name: Name, $Value: Value}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetTag(Id, Callback)
    {
        Database.get('SELECT * FROM Tag WHERE ID_Tag = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllTags(Callback)
    {
        Database.all('SELECT * FROM Tag', Callback)
    }

    static UpdateTag(Id, Name, Value)
    {
        Database.run('UPDATE Tag SET Name = $Name, Value = $Value WHERE ID_Tag = $ID', {$Name: Name, $Value: Value, $ID: Id}, ErrorCallback)
    }

    static DeleteTag(Id)
    {
        Database.run('DELETE FROM Tag WHERE ID_Tag = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.Location = class Location
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateLocation(Type, Location, Callback)
    {
        Database.run('INSERT INTO Location (Type, Location) VALUES ($Type, $Location)', {$Type: Type, $Location: Location}, Callback);
    }

    // The signature of the callback is function(err, row) {}
    static GetLocation(Id, Callback)
    {
        Database.get('SELECT * FROM Location WHERE ID_Location = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllLocations(Callback)
    {
        Database.all('SELECT * FROM Location', Callback)
    }

    static UpdateLocation(Id, Type, Location)
    {
        Database.run('UPDATE Location SET Type = $Type, Location = $Location WHERE ID_Location = $ID', {$Type: Type, $Location: Location, $ID: Id}, ErrorCallback)
    }

    static DeleteLocation(Id)
    {
        Database.run('DELETE FROM Location WHERE ID_Location = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.Collection = class Collection
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateCollection(Name, ID_ParentCollection, Callback)
    {
        Database.run('INSERT INTO Collection (Name, ID_ParentCollection) VALUES ($Name, $ID_ParentCollection)', {$Name: Name, $ID_ParentCollection: ID_ParentCollection}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetCollection(Id, Callback)
    {
        Database.get('SELECT * FROM Collection WHERE ID_Collection = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllCollections(Callback)
    {
        Database.all('SELECT * FROM Collection', Callback)
    }

    static UpdateCollection(Id, Name, ID_ParentCollection)
    {
        Database.run('UPDATE Collection SET Name = $Name, ID_ParentCollection = $ID_ParentCollection WHERE ID_Collection = $ID', {$Name: Name, $ID_ParentCollection: ID_ParentCollection, $ID: Id}, ErrorCallback)
    }

    static DeleteCollection(Id)
    {
        Database.run('DELETE FROM Collection WHERE ID_Collection = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.BLOB = class BLOB
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateBLOB(BLOB, Checksum, Callback)
    {
        Database.run('INSERT INTO BLOB (BLOB, Checksum) VALUES ($BLOB, $Checksum)', {$BLOB: BLOB, $Checksum: Checksum}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetBLOB(Id, Callback)
    {
        Database.get('SELECT * FROM BLOB WHERE ID_BLOB = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllBLOBS(Callback)
    {
        Database.all('SELECT * FROM BLOB', Callback)
    }

    static UpdateBLOB(Id, BLOB, Checksum)
    {
        Database.run('UPDATE BLOB SET BLOB = $BLOB, Checksum = $Checksum WHERE ID_BLOB = $ID', {$BLOB: BLOB, $Checksum: Checksum, $ID: Id}, ErrorCallback)
    }

    static DeleteBLOB(Id)
    {
        Database.run('DELETE FROM BLOB WHERE ID_BLOB = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.File = class File
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateFile(ID_BLOB, Filename, Callback)
    {
        Database.run('INSERT INTO File (ID_BLOB, Filename) VALUES ($ID_BLOB, $Filename)', {$ID_BLOB: ID_BLOB, $Filename: Filename}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetFile(Id, Callback)
    {
        Database.get('SELECT * FROM File WHERE ID_File = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFiles(Callback)
    {
        Database.all('SELECT * FROM File', Callback)
    }

    static UpdateFile(Id, ID_BLOB, Filename)
    {
        Database.run('UPDATE File SET ID_BLOB = $ID_BLOB, Filename = $Filename WHERE ID_File = $ID', {$ID_BLOB: ID_BLOB, $Filename: Filename, $ID: Id}, ErrorCallback)
    }

    static DeleteFile(Id)
    {
        Database.run('DELETE FROM File WHERE ID_File = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.File_Tag = class File_Tag
{
    static CreateFile_Tag(ID_File, ID_Tag)
    {
        Database.run('INSERT INTO File_Tag (ID_File, ID_Tag) VALUES ($ID_File, $ID_Tag)', {$ID_File: ID_File, $ID_Tag: ID_Tag}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Tag(ID_File, ID_Tag, Callback)
    {
        if(ID_File == null && ID_Tag == null)
        {
            Database.all('SELECT * FROM File_Tag', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_Tag = $ID_Tag', {$ID_Tag: ID_Tag}, Callback)
        }
        else if(ID_Tag == null)
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag', {$ID_File: ID_File, $ID_Tag: ID_Tag}, Callback)
        }
    }

    static UpdateFile_Tag(ID_File, ID_Tag, New_ID_File, New_ID_Tag)
    {
        Database.run('UPDATE File_Tag SET ID_File = $New_ID_File, ID_Tag = $New_ID_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag', {$ID_File: ID_File, $ID_Tag: ID_Tag, $New_ID_File: New_ID_File, $New_ID_Tag: New_ID_Tag}, ErrorCallback)
    }

    static DeleteFile_Tag(ID_File, ID_Tag)
    {
        Database.run('DELETE FROM File_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag',{$ID_File: ID_File, $ID_Tag: ID_Tag}, ErrorCallback)
    }
}

DatabaseOperation.File_Location = class File_Location
{
    static CreateFile_Location(ID_File, ID_Location)
    {
        Database.run('INSERT INTO File_Location (ID_File, ID_Location) VALUES ($ID_File, $ID_Location)', {$ID_File: ID_File, $ID_Location: ID_Location}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Location(ID_File, ID_Location, Callback)
    {
        if(ID_File == null && ID_Location == null)
        {
            Database.all('SELECT * FROM File_Location', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Location WHERE ID_Location = $ID_Location', {$ID_Location: ID_Location}, Callback)
        }
        else if(ID_Location == null)
        {
            Database.all('SELECT * FROM File_Location WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location', {$ID_File: ID_File, $ID_Location: ID_Location}, Callback)
        }
    }

    static UpdateFile_Location(ID_File, ID_Location, New_ID_File, New_ID_Location)
    {
        Database.run('UPDATE File_Location SET ID_File = $New_ID_File, ID_Location = $New_ID_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location', {$ID_File: ID_File, $ID_Location: ID_Location, $New_ID_File: New_ID_File, $New_ID_Location: New_ID_Location}, ErrorCallback)
    }

    static DeleteFile_Location(ID_File, ID_Location)
    {
        Database.run('DELETE FROM File_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location',{$ID_File: ID_File, $ID_Location: ID_Location}, ErrorCallback)
    }
}

DatabaseOperation.File_Collection = class File_Collection
{
    static CreateFile_Collection(ID_File, ID_Collection)
    {
        Database.run('INSERT INTO File_Collection (ID_File, ID_Collection) VALUES ($ID_File, $ID_Collection)', {$ID_File: ID_File, $ID_Collection: ID_Collection}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Collection(ID_File, ID_Collection, Callback)
    {
        if(ID_File == null && ID_Collection == null)
        {
            Database.all('SELECT * FROM File_Collection', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_Collection = $ID_Collection', {$ID_Collection: ID_Collection}, Callback)
        }
        else if(ID_Collection == null)
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection', {$ID_File: ID_File, $ID_Collection: ID_Collection}, Callback)
        }
    }

    static UpdateFile_Collection(ID_File, ID_Collection, New_ID_File, New_ID_Collection)
    {
        Database.run('UPDATE File_Collection SET ID_File = $New_ID_File, ID_Collection = $New_ID_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection', {$ID_File: ID_File, $ID_Collection: ID_Collection, $New_ID_File: New_ID_File, $New_ID_Collection: New_ID_Collection}, ErrorCallback)
    }

    static DeleteFile_Collection(ID_File, ID_Collection)
    {
        Database.run('DELETE FROM File_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection',{$ID_File: ID_File, $ID_Collection: ID_Collection}, ErrorCallback)
    }
}

exports.Database = Database;
exports.DatabaseOperation = DatabaseOperation;

function ErrorCallback(err)
{
    if(err != null)
    {
        console.log(err.message);
    }
}<commit_msg>move Checksum from BLOB to File table<commit_after>/**
 * Created by Daniel on 2016-10-21.
 */
const sqlite3 = require('sqlite3').verbose()
const Database = new sqlite3.Database('Database.sqlite3').run('PRAGMA foreign_keys = ON')

class DatabaseOperation
{
    static CreateTables()
    {
        Database.serialize(function ()
        {
            Database.run('create table if not exists Tag(ID_Tag INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, Value TEXT)', ErrorCallback)
            Database.run('create table if not exists BLOB(ID_BLOB INTEGER PRIMARY KEY AUTOINCREMENT, BLOB BLOB)', ErrorCallback)
            Database.run('create table if not exists Location(ID_Location INTEGER PRIMARY KEY AUTOINCREMENT, Type TEXT, Location TEXT)', ErrorCallback)
            Database.run('create table if not exists File(ID_File INTEGER PRIMARY KEY AUTOINCREMENT, Filename TEXT, ID_BLOB INTEGER, Checksum TEXT, FOREIGN KEY(ID_BLOB) REFERENCES BLOB(ID_BLOB))', ErrorCallback)
            Database.run('create table if not exists Collection(ID_Collection INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, ID_ParentCollection INTEGER, FOREIGN KEY(ID_ParentCollection) REFERENCES Collection(ID_Collection))', ErrorCallback)
            Database.run('create table if not exists File_Collection(ID_File INTEGER NOT NULL, ID_Collection INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Collection) REFERENCES Collection(ID_Collection), PRIMARY KEY(ID_File, ID_Collection))', ErrorCallback)
            Database.run('create table if not exists File_Location(ID_File INTEGER NOT NULL, ID_Location INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Location) REFERENCES Location(ID_Location), PRIMARY KEY(ID_File, ID_Location))', ErrorCallback)
            Database.run('create table if not exists File_Tag(ID_File INTEGER NOT NULL, ID_Tag INTEGER NOT NULL, FOREIGN KEY(ID_File) REFERENCES File(ID_File), FOREIGN KEY(ID_Tag) REFERENCES Tag(ID_Tag), PRIMARY KEY(ID_File, ID_Tag))', ErrorCallback)
        })
    }

    static DropTables()
    {
        Database.serialize(function ()
        {
            Database.run('drop table if exists File_Tag', ErrorCallback)
            Database.run('drop table if exists File_Location', ErrorCallback)
            Database.run('drop table if exists File_Collection', ErrorCallback)
            Database.run('drop table if exists Collection', ErrorCallback)
            Database.run('drop table if exists File', ErrorCallback)
            Database.run('drop table if exists Location', ErrorCallback)
            Database.run('drop table if exists BLOB', ErrorCallback)
            Database.run('drop table if exists Tag', ErrorCallback)
        })
    }

    static  ShowTables()
    {
        Database.all("select name from sqlite_master where type='table'", function (err, tables)
        {
            console.log(tables)
        })
    }
}

DatabaseOperation.Tag = class Tag
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateTag(Name, Value, Callback)
    {
        Database.run('INSERT INTO Tag (Name, Value) VALUES ($Name, $Value)', {$Name: Name, $Value: Value}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetTag(Id, Callback)
    {
        Database.get('SELECT * FROM Tag WHERE ID_Tag = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllTags(Callback)
    {
        Database.all('SELECT * FROM Tag', Callback)
    }

    static UpdateTag(Id, Name, Value)
    {
        Database.run('UPDATE Tag SET Name = $Name, Value = $Value WHERE ID_Tag = $ID', {$Name: Name, $Value: Value, $ID: Id}, ErrorCallback)
    }

    static DeleteTag(Id)
    {
        Database.run('DELETE FROM Tag WHERE ID_Tag = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.Location = class Location
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateLocation(Type, Location, Callback)
    {
        Database.run('INSERT INTO Location (Type, Location) VALUES ($Type, $Location)', {$Type: Type, $Location: Location}, Callback);
    }

    // The signature of the callback is function(err, row) {}
    static GetLocation(Id, Callback)
    {
        Database.get('SELECT * FROM Location WHERE ID_Location = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllLocations(Callback)
    {
        Database.all('SELECT * FROM Location', Callback)
    }

    static UpdateLocation(Id, Type, Location)
    {
        Database.run('UPDATE Location SET Type = $Type, Location = $Location WHERE ID_Location = $ID', {$Type: Type, $Location: Location, $ID: Id}, ErrorCallback)
    }

    static DeleteLocation(Id)
    {
        Database.run('DELETE FROM Location WHERE ID_Location = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.Collection = class Collection
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateCollection(Name, ID_ParentCollection, Callback)
    {
        Database.run('INSERT INTO Collection (Name, ID_ParentCollection) VALUES ($Name, $ID_ParentCollection)', {$Name: Name, $ID_ParentCollection: ID_ParentCollection}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetCollection(Id, Callback)
    {
        Database.get('SELECT * FROM Collection WHERE ID_Collection = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllCollections(Callback)
    {
        Database.all('SELECT * FROM Collection', Callback)
    }

    static UpdateCollection(Id, Name, ID_ParentCollection)
    {
        Database.run('UPDATE Collection SET Name = $Name, ID_ParentCollection = $ID_ParentCollection WHERE ID_Collection = $ID', {$Name: Name, $ID_ParentCollection: ID_ParentCollection, $ID: Id}, ErrorCallback)
    }

    static DeleteCollection(Id)
    {
        Database.run('DELETE FROM Collection WHERE ID_Collection = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.BLOB = class BLOB
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateBLOB(BLOB, Callback)
    {
        Database.run('INSERT INTO BLOB (BLOB) VALUES ($BLOB)', {$BLOB: BLOB}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetBLOB(Id, Callback)
    {
        Database.get('SELECT * FROM BLOB WHERE ID_BLOB = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllBLOBS(Callback)
    {
        Database.all('SELECT * FROM BLOB', Callback)
    }

    static UpdateBLOB(Id, BLOB)
    {
        Database.run('UPDATE BLOB SET BLOB = $BLOB WHERE ID_BLOB = $ID', {$BLOB: BLOB, $ID: Id}, ErrorCallback)
    }

    static DeleteBLOB(Id)
    {
        Database.run('DELETE FROM BLOB WHERE ID_BLOB = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.File = class File
{
    // The signature of the callback is function(err) {}
    // If execution was successful, the this object will contain property named lastID
    static CreateFile(ID_BLOB, Filename, Checksum, Callback)
    {
        Database.run('INSERT INTO File (ID_BLOB, Filename, Checksum) VALUES ($ID_BLOB, $Filename, $Checksum)', {$ID_BLOB: ID_BLOB, $Filename: Filename, $Checksum: Checksum}, Callback)
    }

    // The signature of the callback is function(err, row) {}
    static GetFile(Id, Callback)
    {
        Database.get('SELECT * FROM File WHERE ID_File = $ID', {$ID: Id}, Callback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFiles(Callback)
    {
        Database.all('SELECT * FROM File', Callback)
    }

    static UpdateFile(Id, ID_BLOB, Filename, Checksum)
    {
        Database.run('UPDATE File SET ID_BLOB = $ID_BLOB, Filename = $Filename, Checksum = $Checksum WHERE ID_File = $ID', {$ID_BLOB: ID_BLOB, $Filename: Filename, $Checksum: Checksum, $ID: Id}, ErrorCallback)
    }

    static DeleteFile(Id)
    {
        Database.run('DELETE FROM File WHERE ID_File = $ID',{$ID: Id}, ErrorCallback)
    }
}

DatabaseOperation.File_Tag = class File_Tag
{
    static CreateFile_Tag(ID_File, ID_Tag)
    {
        Database.run('INSERT INTO File_Tag (ID_File, ID_Tag) VALUES ($ID_File, $ID_Tag)', {$ID_File: ID_File, $ID_Tag: ID_Tag}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Tag(ID_File, ID_Tag, Callback)
    {
        if(ID_File == null && ID_Tag == null)
        {
            Database.all('SELECT * FROM File_Tag', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_Tag = $ID_Tag', {$ID_Tag: ID_Tag}, Callback)
        }
        else if(ID_Tag == null)
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag', {$ID_File: ID_File, $ID_Tag: ID_Tag}, Callback)
        }
    }

    static UpdateFile_Tag(ID_File, ID_Tag, New_ID_File, New_ID_Tag)
    {
        Database.run('UPDATE File_Tag SET ID_File = $New_ID_File, ID_Tag = $New_ID_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag', {$ID_File: ID_File, $ID_Tag: ID_Tag, $New_ID_File: New_ID_File, $New_ID_Tag: New_ID_Tag}, ErrorCallback)
    }

    static DeleteFile_Tag(ID_File, ID_Tag)
    {
        Database.run('DELETE FROM File_Tag WHERE ID_File = $ID_File and ID_Tag = $ID_Tag',{$ID_File: ID_File, $ID_Tag: ID_Tag}, ErrorCallback)
    }
}

DatabaseOperation.File_Location = class File_Location
{
    static CreateFile_Location(ID_File, ID_Location)
    {
        Database.run('INSERT INTO File_Location (ID_File, ID_Location) VALUES ($ID_File, $ID_Location)', {$ID_File: ID_File, $ID_Location: ID_Location}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Location(ID_File, ID_Location, Callback)
    {
        if(ID_File == null && ID_Location == null)
        {
            Database.all('SELECT * FROM File_Location', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Location WHERE ID_Location = $ID_Location', {$ID_Location: ID_Location}, Callback)
        }
        else if(ID_Location == null)
        {
            Database.all('SELECT * FROM File_Location WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location', {$ID_File: ID_File, $ID_Location: ID_Location}, Callback)
        }
    }

    static UpdateFile_Location(ID_File, ID_Location, New_ID_File, New_ID_Location)
    {
        Database.run('UPDATE File_Location SET ID_File = $New_ID_File, ID_Location = $New_ID_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location', {$ID_File: ID_File, $ID_Location: ID_Location, $New_ID_File: New_ID_File, $New_ID_Location: New_ID_Location}, ErrorCallback)
    }

    static DeleteFile_Location(ID_File, ID_Location)
    {
        Database.run('DELETE FROM File_Location WHERE ID_File = $ID_File and ID_Location = $ID_Location',{$ID_File: ID_File, $ID_Location: ID_Location}, ErrorCallback)
    }
}

DatabaseOperation.File_Collection = class File_Collection
{
    static CreateFile_Collection(ID_File, ID_Collection)
    {
        Database.run('INSERT INTO File_Collection (ID_File, ID_Collection) VALUES ($ID_File, $ID_Collection)', {$ID_File: ID_File, $ID_Collection: ID_Collection}, ErrorCallback)
    }

    // The signature of the callback is function(err, rows) {}
    static GetAllFile_Collection(ID_File, ID_Collection, Callback)
    {
        if(ID_File == null && ID_Collection == null)
        {
            Database.all('SELECT * FROM File_Collection', Callback)
        }
        else if(ID_File == null)
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_Collection = $ID_Collection', {$ID_Collection: ID_Collection}, Callback)
        }
        else if(ID_Collection == null)
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_File = $ID_File', {$ID_File: ID_File}, Callback)
        }
        else
        {
            Database.all('SELECT * FROM File_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection', {$ID_File: ID_File, $ID_Collection: ID_Collection}, Callback)
        }
    }

    static UpdateFile_Collection(ID_File, ID_Collection, New_ID_File, New_ID_Collection)
    {
        Database.run('UPDATE File_Collection SET ID_File = $New_ID_File, ID_Collection = $New_ID_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection', {$ID_File: ID_File, $ID_Collection: ID_Collection, $New_ID_File: New_ID_File, $New_ID_Collection: New_ID_Collection}, ErrorCallback)
    }

    static DeleteFile_Collection(ID_File, ID_Collection)
    {
        Database.run('DELETE FROM File_Collection WHERE ID_File = $ID_File and ID_Collection = $ID_Collection',{$ID_File: ID_File, $ID_Collection: ID_Collection}, ErrorCallback)
    }
}

exports.Database = Database;
exports.DatabaseOperation = DatabaseOperation;

function ErrorCallback(err)
{
    if(err != null)
    {
        console.log(err.message);
    }
}<|endoftext|>