• R/O
  • HTTP
  • SSH
  • HTTPS

AI004: コミット

サブプロジェクトAI004


コミットメタ情報

リビジョン07ec1ee2ceaa28ccab74530d1fc4718cc8f38d2c (tree)
日時2014-04-28 21:42:55
作者hikarupsp <hikarupsp@user...>
コミッターhikarupsp

ログメッセージ

ノードの更新が反映されるようになった

変更サマリ

差分

--- a/memdb/memdb.js
+++ b/memdb/memdb.js
@@ -11,12 +11,13 @@ function MemoryDB(syncPHPURL){
1111 this.syncPHPURL = syncPHPURL;
1212 this.isEnabledNetDB = true;
1313 //
14- this.callback_refreshedNode = null; // function(nodeinstance){};
14+ this.callback_updatedNode = null; // function(nodeinstance){};
1515 }
1616 MemoryDB.prototype = {
1717 UUID_Null: "00000000-0000-0000-0000-000000000000",
1818 UUID_NodeType_DecimalNumber: "e3346fd4-ac17-41c3-b3c7-e04972e5c014",
1919 UUID_Node_MemoryDBNetworkTimestamp: "a2560a9c-dcf7-4746-ac14-347188518cf2",
20+ UUID_Node_MemoryDBNetworkResponseCode: "1eeb6d3d-751f-444f-91c8-ed940e65f8bd",
2021 createRequestObject: function(){
2122 var rq = null;
2223 // XMLHttpRequest
@@ -94,11 +95,11 @@ MemoryDB.prototype = {
9495 if(d === undefined){
9596 continue;
9697 }
97- this.refreshNodeInternal(d[2], d[1], d[0]);
98+ this.updateNodeInternal(d[2], d[1], d[0]);
9899 }
99- console.log(this.root);
100+ //console.log(this.root);
100101 },
101- refreshNode: function(ident, tid, nid){
102+ updateNode: function(ident, tid, nid){
102103 // 該当タグのデータを書き換え、もしくは新規作成する。
103104 // 可能であればネットワークに反映する
104105 // nid(nodeid)は省略可能で、省略時は新たなUUIDが自動的に付与される
@@ -106,9 +107,9 @@ MemoryDB.prototype = {
106107 // identはnullもしくは空文字でもかまわない。
107108 // 戻り値はMemoryDBNodeTagインスタンス
108109 // エラー発生時はundefinedを返す。
109- this.refreshNodeInternal(ident, tid, nid, true);
110+ this.updateNodeInternal(ident, tid, nid, true);
110111 },
111- refreshNodeInternal: function(ident, tid, nid, enableSync){
112+ updateNodeInternal: function(ident, tid, nid, enableSync){
112113 // 基本的にローカルデータのみ変更
113114 // enableSync == trueでネットワーク同期する
114115 var t, s, r;
@@ -122,7 +123,16 @@ MemoryDB.prototype = {
122123 t = this.getNodeFromUUID(nid);
123124 if(t){
124125 // 変更
125- return undefined;
126+ t.typeid = tid;
127+ t.identifier = ident;
128+ if(enableSync && this.isEnabledNetDB){
129+ s = this.syncPHPURL + "?action=updatenode";
130+ s += "&nid=" + encodeURIComponent(nid);
131+ s += "&tid=" + encodeURIComponent(tid);
132+ s += "&ident=" + encodeURIComponent(ident);
133+ r = this.sendRequestSync("GET", s, null);
134+ //console.log(r);
135+ }
126136 } else{
127137 // 新規作成
128138 t = new MemoryDBNodeTag(nid, tid, ident);
@@ -134,11 +144,11 @@ MemoryDB.prototype = {
134144 s += "&tid=" + encodeURIComponent(tid);
135145 s += "&ident=" + encodeURIComponent(ident);
136146 r = this.sendRequestSync("GET", s, null);
137- console.log(r);
147+ //console.log(r);
138148 }
139149 }
140- if(this.callback_refreshedNode){
141- this.callback_refreshedNode(t);
150+ if(this.callback_updatedNode){
151+ this.callback_updatedNode(t);
142152 }
143153 },
144154 createUUID: function(){
--- a/memdb/memdb.php
+++ b/memdb/memdb.php
@@ -37,7 +37,6 @@ create table Edge (
3737 ");
3838
3939 //
40-
4140 define("QUERY_ADD_Node", "
4241 insert into Node (
4342 nodeid, typeid, identifier, modtimestamp
@@ -46,7 +45,7 @@ insert into Node (
4645 )
4746 ");
4847 define("QUERY_ADD_Node_TYPES", "sssi");
49-
48+//
5049 define("QUERY_ADD_Edge", "
5150 insert into Node (
5251 edgeid, typeid, nodeid0, nodeid1, modtimestamp
@@ -55,7 +54,14 @@ insert into Node (
5554 )
5655 ");
5756 define("QUERY_ADD_Edge_TYPES", "ssssi");
58-
57+//
58+define("QUERY_UPDATE_Node", "
59+UPDATE Node SET
60+ typeid=unhex(replace(?, '-', '')), identifier=?, modtimestamp=?
61+WHERE
62+ nodeid=unhex(replace(?, '-', ''))
63+");
64+define("QUERY_UPDATE_Node_TYPES", "ssis");
5965 //
6066
6167 define("QUERY_SELECT_ALL_Node", "select hex(nodeid), hex(typeid), identifier from Node");
@@ -87,14 +93,11 @@ if(isset($_GET['action'])){
8793
8894 $stmt->bind_result($uuid, $typeid, $ident);
8995 while($stmt->fetch()){
90- $uuid = strtolower($uuid);
91- echo('["');
92- echo(getFormedUUIDString($uuid));
93- echo('","');
94- echo(getFormedUUIDString($typeid));
95- echo('","');
96- echo($ident);
97- echo('"]');
96+ echoNode(
97+ getFormedUUIDString($uuid),
98+ getFormedUUIDString($typeid),
99+ $ident
100+ );
98101 echo(PHP_EOL);
99102 }
100103 $stmt->close();
@@ -118,14 +121,11 @@ if(isset($_GET['action'])){
118121
119122 $stmt->bind_result($uuid, $typeid, $ident);
120123 while($stmt->fetch()){
121- $uuid = strtolower($uuid);
122- echo('["');
123- echo(getFormedUUIDString($uuid));
124- echo('","');
125- echo(getFormedUUIDString($typeid));
126- echo('","');
127- echo($ident);
128- echo('"]');
124+ echoNode(
125+ getFormedUUIDString($uuid),
126+ getFormedUUIDString($typeid),
127+ $ident
128+ );
129129 echo(PHP_EOL);
130130 }
131131 $stmt->close();
@@ -143,14 +143,11 @@ if(isset($_GET['action'])){
143143
144144 $stmt->bind_result($uuid, $typeid, $ident, $mts);
145145 while($stmt->fetch()){
146- $uuid = strtolower($uuid);
147- echo('["');
148- echo(getFormedUUIDString($uuid));
149- echo('","');
150- echo(getFormedUUIDString($typeid));
151- echo('","');
152- echo($ident);
153- echo('"]');
146+ echoNode(
147+ getFormedUUIDString($uuid),
148+ getFormedUUIDString($typeid),
149+ $ident
150+ );
154151 echo(' @' . $mts);
155152 echo("<br />");
156153 }
@@ -184,29 +181,59 @@ if(isset($_GET['action'])){
184181 exitWithResponseCode("A0518702-C90C-4785-B5EA-1A213DD0205B", mysqli_error($db));
185182 }
186183 $stmt->close();
187- exitWithResponseCode("CEA95615-649C-4837-9E24-0C968FA57647", "OK");
188- } else if(strcmp($action, 'saytest') == 0){
189- /*
190- //for Mac OSX say command.
191- system("say " . escapeshellarg("sayのテストをしています。"));
192- */
184+ exitWithResponseCode("cea95615-649c-4837-9e24-0c968fa57647", "OK");
185+ } else if(strcmp($action, 'updatenode') == 0){
186+ if(isset($_GET['nid'])){
187+ $nodeid = $_GET['nid'];
188+ } else{
189+ exitWithResponseCode("A0518702-C90C-4785-B5EA-1A213DD0205B", "nodeid needed.");
190+ }
191+ if(isset($_GET['tid'])){
192+ $typeid = $_GET['tid'];
193+ } else{
194+ exitWithResponseCode("A0518702-C90C-4785-B5EA-1A213DD0205B", "typeid needed.");
195+ }
196+ if(isset($_GET['ident'])){
197+ $ident = $_GET['ident'];
198+ } else{
199+ exitWithResponseCode("A0518702-C90C-4785-B5EA-1A213DD0205B", "ident needed.");
200+ }
201+
202+ $stmt = $db->prepare(QUERY_UPDATE_Node);
203+ $mts = getTimeStampMs();
204+ $stmt->bind_param(QUERY_UPDATE_Node_TYPES, $typeid, $ident, $mts, $nodeid);
205+ $stmt->execute();
206+ //
207+ $stmt->store_result();
208+ if($stmt->errno != 0){
209+ exitWithResponseCode("A0518702-C90C-4785-B5EA-1A213DD0205B", mysqli_error($db));
210+ }
211+ $stmt->close();
212+ exitWithResponseCode("cea95615-649c-4837-9e24-0c968fa57647", "OK");
193213 }
194214 }
195215
196216 //NOP error
197-exitWithResponseCode("B539657C-0FA6-49C2-AFB0-13AF5C7866ED");
217+exitWithResponseCode("b539657c-0fa6-49c2-afb0-13af5c7866ed");
198218
199219 function exitWithResponseCode($errid, $description = "")
200220 {
201- die('["' . $errid .'","' . $description . '"]');
221+ echoNode("1eeb6d3d-751f-444f-91c8-ed940e65f8bd", $errid, $description);
222+ exit();
202223 }
203224
204225 function echoMemoryDBNetworkTimestamp()
205226 {
206- echo('["a2560a9c-dcf7-4746-ac14-347188518cf2","e3346fd4-ac17-41c3-b3c7-e04972e5c014","');
207- echo(getTimeStampMs());
208- echo('"]');
209- echo(PHP_EOL);
227+ echoNode(
228+ "a2560a9c-dcf7-4746-ac14-347188518cf2",
229+ "e3346fd4-ac17-41c3-b3c7-e04972e5c014",
230+ getTimeStampMs()
231+ );
232+}
233+
234+function echoNode($nid, $tid, $ident)
235+{
236+ echo('["' . $nid .'","' . $tid .'","' . $ident . '"]');
210237 }
211238
212239 function connectDB()
--- a/mgcanvas/index.html
+++ b/mgcanvas/index.html
@@ -43,7 +43,7 @@ onload = function() {
4343 identifier:<input id="identBox" type="text"></input>
4444 <br />
4545 <button onclick="mgmain.setIdentifierForSelectedNode(getElementById('identBox').value);">setNodeIdent</button>
46-<button onclick="memdb.refreshNode(getElementById('identBox').value);">addNode</button>
46+<button onclick="memdb.updateNode(getElementById('identBox').value);">addNode</button>
4747
4848 </body>
4949 </html>
\ No newline at end of file
--- a/mgcanvas/mgcanvas.js
+++ b/mgcanvas/mgcanvas.js
@@ -85,10 +85,18 @@ MGCanvas.prototype = {
8585 setSourceMemoryDB: function(mdb){
8686 var that = this;
8787 this.srcMemoryDB = mdb;
88- mdb.callback_refreshedNode = function(t){
88+ mdb.callback_updatedNode = function(t){
8989 var n;
90- n = new MGNode(that, t.identifier);
91- that.nodeList.push(n);
90+ n = that.nodeList.isIncluded(t.nodeid, function(a, b){ return a.nodeid == b; });
91+ if(!n){
92+ // 新規追加
93+ n = new MGNode(that, t.identifier);
94+ n.nodeid = t.nodeid;
95+ that.nodeList.push(n);
96+ } else{
97+ // 更新
98+ n.identifier = t.identifier;
99+ }
92100 }
93101 },
94102 bringToCenter: function(){
@@ -434,14 +442,23 @@ MGCanvas.prototype = {
434442 },
435443 setIdentifierForSelectedNode: function(str){
436444 if(this.selectedNode){
437- this.selectedNode.identifier = str;
445+ if(this.srcMemoryDB){
446+ this.srcMemoryDB.updateNode(str, this.selectedNode.typeid, this.selectedNode.nodeid);
447+ } else{
448+ this.selectedNode.identifier = str;
449+ }
438450 }
439451 },
440452 }
441453
442454 function MGNode(env, identifier){
443455 this.env = env;
456+ //
444457 this.identifier = identifier;
458+ //
459+ this.nodeid = undefined;
460+ this.typeid = undefined;
461+ //
445462 this.position = new Point2D(Math.random() * 32 - 16, Math.random() * 32 - 16);
446463 this.size = 10;
447464 //ランダムな初期ベクトルをもつ。
旧リポジトリブラウザで表示