Skip to content

Commit fe4f1c9

Browse files
committed
image search bug fix
1 parent 9925ac8 commit fe4f1c9

File tree

5 files changed

+68
-121
lines changed

5 files changed

+68
-121
lines changed

app/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "conet",
3-
"version": "3.0.10",
3+
"version": "3.0.11",
44
"license": "MIT",
55
"description": "CoNET",
66
"repository": {

app/public/scripts/appsManager.js

Lines changed: 22 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -452,21 +452,6 @@ const _appScript = {
452452
this.showHtmlCodePage(true);
453453
this.showImgPage(false);
454454
}
455-
getimageData(val, mine, CallBack) {
456-
const img = document.createElement('img');
457-
const contentBlob = new Blob([val], { type: mine });
458-
const url = window.URL.createObjectURL(contentBlob);
459-
img.addEventListener('loadend', e => {
460-
window.URL.revokeObjectURL(url);
461-
const uu = $(`${img.id}`);
462-
const ret = uu.attr('src');
463-
uu.remove();
464-
return CallBack(null, ret);
465-
});
466-
img.id = uuid_generate();
467-
img.src = url;
468-
$('#tempDom').append(img);
469-
}
470455
},
471456
info: {
472457
totalResults: ['大约有', '約', 'About', '大約有'],
@@ -524,6 +509,9 @@ const _appScript = {
524509
imageLoadingGetResponse: ko.observable(false),
525510
imageConetResponse: ko.observable(false),
526511
imageItemsArray: ko.observable(),
512+
searchSimilarImagesList: ko.observableArray([]),
513+
showSearchSimilarImagesResult: ko.observable(false),
514+
imageSearchItemArray: ko.observable(),
527515
videoButtonShowLoading: ko.observable(false),
528516
videoItemsArray: ko.observable(),
529517
videoButtonShowError: ko.observable(false),
@@ -533,11 +521,7 @@ const _appScript = {
533521
nextButtonErrorIndex: ko.observable(false),
534522
nextButtonConetResponse: ko.observable(false),
535523
nextButtonLoadingGetResponse: ko.observable(false),
536-
searchSimilarImagesList: ko.observableArray([]),
537-
showSearchSimilarImagesResult: ko.observable(false),
538524
// ['originImage']
539-
similarImagesLoading: ko.observable(false),
540-
showSimilarImagesError: ko.observable(false),
541525
initSearchData: (self) => {
542526
self.searchItem(null);
543527
self.searchItemList([]);
@@ -546,14 +530,8 @@ const _appScript = {
546530
self.newsItemsArray(null);
547531
self.imageItemsArray(null);
548532
self.showSearchesRelated(null);
549-
self.searchSimilarImagesList([]);
550533
self.videoItemsArray(null);
551-
},
552-
similarImagesReadyClick: (self, event) => {
553-
},
554-
requestSimilarImagesClick: (self, e) => {
555-
},
556-
SimilarImagesErrorClick: (self, e) => {
534+
self.imageSearchItemArray(null);
557535
},
558536
showResultItems: (self, items) => {
559537
self.searchItem(items);
@@ -886,9 +864,10 @@ const _appScript = {
886864
return self.imageButtonShowError(true);
887865
};
888866
if (!self.imageItemsArray()) {
867+
const imageLink = self.searchItemsArray() && self.searchItemsArray().action && self.searchItemsArray().action.image ? self.searchItemsArray().action.image : self.imageSearchItemArray().searchesRelated[1];
889868
const com = {
890869
command: 'CoSearch',
891-
Args: ['google', self.searchItemsArray().action.image],
870+
Args: ['google', imageLink],
892871
error: null,
893872
subCom: 'imageNext'
894873
};
@@ -1100,6 +1079,21 @@ const _appScript = {
11001079
//return CallBack ( null, ret )
11011080
},
11021081
imageSearch: (ee) => {
1082+
const self = _view.appsManager().appScript();
1083+
const errorProcess = (err) => {
1084+
self.showInputLoading(false);
1085+
self.searchInputText('');
1086+
self.errorMessageIndex(_view.connectInformationMessage.getErrorIndex(err));
1087+
return self.showSearchError(true);
1088+
};
1089+
const showItems = (iResult) => {
1090+
self.showInputLoading(false);
1091+
self.currentlyShowItems(2);
1092+
self.returnSearchResultItemsInit(iResult);
1093+
self.imageSearchItemArray(iResult);
1094+
self.searchInputText(iResult.searchesRelated[0]);
1095+
self.showResultItems(self, self.imageSearchItemArray());
1096+
};
11031097
if (!ee || !ee.files || !ee.files.length) {
11041098
return;
11051099
}
@@ -1109,18 +1103,11 @@ const _appScript = {
11091103
}
11101104
const reader = new FileReader();
11111105
reader.onload = e => {
1112-
const self = _view.appsManager().appScript();
11131106
const rawData = reader.result.toString();
11141107
self.showInputLoading(true);
11151108
self.searchInputText(' ');
11161109
self.searchItem(null);
11171110
self.searchItemList([]);
1118-
const errorProcess = (err) => {
1119-
self.showInputLoading(false);
1120-
self.searchInputText('');
1121-
self.errorMessageIndex(_view.connectInformationMessage.getErrorIndex(err));
1122-
return self.showSearchError(true);
1123-
};
11241111
return self.getPictureBase64MaxSize_mediaData(rawData, 1024, 1024, (err, data) => {
11251112
if (err) {
11261113
return errorProcess(err);
@@ -1155,13 +1142,7 @@ const _appScript = {
11551142
if (com.error) {
11561143
return errorProcess(com.error);
11571144
}
1158-
self.showInputLoading(false);
1159-
const iResult = com.Args.param;
1160-
self.currentlyShowItems(2);
1161-
self.returnSearchResultItemsInit(iResult);
1162-
self.imageItemsArray(iResult);
1163-
self.searchInputText(iResult.searchesRelated[0]);
1164-
self.showResultItems(self, self.imageItemsArray());
1145+
return showItems(com.Args.param);
11651146
});
11661147
});
11671148
});

app/public/scripts/appsManager.ts

Lines changed: 31 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11

2-
32
const testHtml = '<div id="mainMenu" data-bind="with: mainScript " style="margin-top: 2em;"><div class="ui divider"></div><div class="ui header AppListHeader" style="color: cornsilk;"><div class="content"><span data-bind=" text: infoDefine[ $root.languageIndex() ].appsManager.nodeName"></span><span data-bind=" text: nodeName [$root.languageIndex() ]" style="color: lightcyan;"></span><div class="sub header" style="color: cornsilk;"><span data-bind=" text: infoDefine[ $root.languageIndex() ].appsManager.connectAddress "></span><span data-bind=" text: nodeAddress " style="color: lightcyan;"></span></div></div></div><div class="ui header AppListHeader" style=" color: white;"><div class="content"><h2 data-bind=" text: infoDefine[ $root.languageIndex() ].appsManager.serviceList"></h2></div></div><div class="ui divider"></div><div class="ui items divided" data-bind=" foreach: mainMenuItem"><a class="item AppListHeader"><img class="ui medium image" data-bind=" attr: { src: imgSrc }"><div class="content"><div class="header" data-bind=" text: headerText[ $root.languageIndex()], style: { color: headerTextColor }"></div><div class="meta"><span data-bind=" text: meta[ $root.languageIndex() ], style: { color: textColor }"></span></div><div class="description"><p data-bind="text: description[ $root.languageIndex() ], style: { color: textColor } "></p></div><div class="extra" data-bind=" html: extra [ $root.languageIndex() ], style: { color: textColor } "></div></div></a></div></div>'
43

54
const _mainMenuObj = {
@@ -416,24 +415,6 @@ const _appScript = {
416415
this.showImgPage ( false )
417416
}
418417

419-
private getimageData ( val: any, mine: string, CallBack ) {
420-
const img = document.createElement('img')
421-
const contentBlob = new Blob ([ val ], { type: mine })
422-
const url = window.URL.createObjectURL ( contentBlob )
423-
424-
img.addEventListener ( 'loadend', e => {
425-
window.URL.revokeObjectURL ( url )
426-
const uu = $( `${ img.id }`)
427-
const ret = uu.attr ('src')
428-
uu.remove ()
429-
return CallBack ( null, ret )
430-
})
431-
432-
img.id = uuid_generate ()
433-
img.src = url
434-
$('#tempDom').append ( img )
435-
}
436-
437418
constructor ( public showUrl: string, private zipBase64Stream: string, private zipBase64StreamUuid: string, private exit: ()=> void ) {
438419
const self = this
439420
_view.showIconBar ( false )
@@ -559,6 +540,9 @@ const _appScript = {
559540
imageLoadingGetResponse: ko.observable ( false ),
560541
imageConetResponse: ko.observable ( false ),
561542
imageItemsArray: ko.observable (),
543+
searchSimilarImagesList: ko.observableArray ([]),
544+
showSearchSimilarImagesResult: ko.observable ( false ),
545+
imageSearchItemArray: ko.observable (),
562546

563547
videoButtonShowLoading: ko.observable ( false ),
564548
videoItemsArray: ko.observable (),
@@ -571,12 +555,8 @@ const _appScript = {
571555
nextButtonConetResponse: ko.observable ( false ),
572556
nextButtonLoadingGetResponse: ko.observable ( false ),
573557

574-
searchSimilarImagesList: ko.observableArray ([]),
575-
showSearchSimilarImagesResult: ko.observable ( false ),
576558

577559
// ['originImage']
578-
similarImagesLoading: ko.observable ( false ),
579-
showSimilarImagesError: ko.observable ( false ),
580560

581561
initSearchData: ( self ) => {
582562
self.searchItem ( null )
@@ -586,20 +566,8 @@ const _appScript = {
586566
self.newsItemsArray ( null )
587567
self.imageItemsArray ( null )
588568
self.showSearchesRelated ( null )
589-
self.searchSimilarImagesList ( [] )
590569
self.videoItemsArray ( null )
591-
},
592-
593-
similarImagesReadyClick: ( self, event ) => {
594-
595-
},
596-
597-
requestSimilarImagesClick: ( self, e ) => {
598-
599-
},
600-
601-
SimilarImagesErrorClick: ( self, e ) => {
602-
570+
self.imageSearchItemArray ( null )
603571
},
604572

605573
showResultItems: ( self, items ) => {
@@ -1009,6 +977,7 @@ const _appScript = {
1009977
},
1010978

1011979
imageButtonClick: ( self, event ) => {
980+
1012981
if ( self.imageButtonShowLoading ()) {
1013982
return
1014983
}
@@ -1027,10 +996,10 @@ const _appScript = {
1027996
}
1028997

1029998
if ( ! self.imageItemsArray() ) {
1030-
999+
const imageLink = self.searchItemsArray() && self.searchItemsArray().action && self.searchItemsArray().action.image ? self.searchItemsArray().action.image : self.imageSearchItemArray().searchesRelated[1]
10311000
const com: QTGateAPIRequestCommand = {
10321001
command: 'CoSearch',
1033-
Args: [ 'google', self.searchItemsArray().action.image ],
1002+
Args: [ 'google', imageLink ],
10341003
error: null,
10351004
subCom: 'imageNext'
10361005
}
@@ -1311,34 +1280,48 @@ const _appScript = {
13111280

13121281
},
13131282

1283+
1284+
13141285
imageSearch: ( ee ) => {
13151286

1287+
1288+
const self = _view.appsManager().appScript()
1289+
1290+
const errorProcess = ( err ) => {
1291+
self.showInputLoading ( false )
1292+
self.searchInputText ( '' )
1293+
self.errorMessageIndex ( _view.connectInformationMessage.getErrorIndex( err ))
1294+
return self.showSearchError ( true )
1295+
}
1296+
1297+
const showItems = ( iResult ) => {
1298+
self.showInputLoading ( false )
1299+
self.currentlyShowItems ( 2 )
1300+
self.returnSearchResultItemsInit ( iResult )
1301+
self.imageSearchItemArray ( iResult )
1302+
self.searchInputText ( iResult.searchesRelated[0])
1303+
self.showResultItems ( self, self.imageSearchItemArray ())
1304+
}
1305+
13161306
if ( !ee || !ee.files || !ee.files.length ) {
13171307
return
13181308
}
13191309

13201310
const file = ee.files[0]
1311+
13211312
if ( !file || !file.type.match ( /^image.(png$|jpg$|jpeg$|gif$)/ )) {
13221313
return
13231314
}
1324-
13251315
const reader = new FileReader()
13261316

13271317
reader.onload = e => {
1328-
const self = _view.appsManager().appScript()
1318+
13291319
const rawData = reader.result.toString()
13301320
self.showInputLoading ( true )
13311321
self.searchInputText (' ')
13321322
self.searchItem ( null )
13331323
self.searchItemList ([])
13341324

1335-
const errorProcess = ( err ) => {
1336-
self.showInputLoading ( false )
1337-
self.searchInputText ( '' )
1338-
self.errorMessageIndex ( _view.connectInformationMessage.getErrorIndex( err ))
1339-
return self.showSearchError ( true )
1340-
}
1341-
13421325
return self.getPictureBase64MaxSize_mediaData ( rawData, 1024, 1024, ( err, data ) => {
13431326
if ( err ) {
13441327
return errorProcess ( err )
@@ -1386,15 +1369,7 @@ const _appScript = {
13861369
return errorProcess ( com.error )
13871370
}
13881371

1389-
1390-
self.showInputLoading ( false )
1391-
const iResult = com.Args.param
1392-
1393-
self.currentlyShowItems ( 2 )
1394-
self.returnSearchResultItemsInit ( iResult )
1395-
self.imageItemsArray ( iResult )
1396-
self.searchInputText ( iResult.searchesRelated[0])
1397-
self.showResultItems ( self, self.imageItemsArray ())
1372+
return showItems ( com.Args.param )
13981373

13991374
})
14001375
})

app/public/scripts/knockout.js

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/views/Shared/appHtml.pug

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -453,36 +453,26 @@
453453
.meta( data-bind = " text: infoDefine[ $root.languageIndex() ].coSearch.imageSize ")
454454
.description( data-bind = " text: size" style = "color: gray;" )
455455
.meta
456-
457-
<!-- ko if: $parents[0].similarImagesLoading -->
458-
span
459-
i.icon.notched.circle.loading.purple
460-
span.purple( data-bind = " text: infoDefine[ $root.languageIndex() ].coSearch.similarImages" style = "color: #a333c8!important;")
461-
<!-- /ko -->
462456

463-
<!-- ko ifnot: $parents[0].showSimilarImagesError -->
457+
<!-- ko ifnot: $parents[0].imageButtonShowError -->
464458
.notSimilarImagesShowError
465459

466-
<!-- ko ifnot: $parents[0].similarImagesLoading -->
467-
.ifNotSimilarImagesLoading
468-
469-
<!-- ko if: $parents[0].searchSimilarImagesList().length -->
470-
.ifHaveSearchSimilarImagesList
471-
i.icon.file.image.outline.orange.link( data-bind = "click: $parents[0].similarImagesReadyClick ")
472-
a.ui( data-bind = " text: infoDefine[ $root.languageIndex() ].coSearch.similarImages, click: $parents[0].similarImagesReadyClick ", style = "color:orange!important" )
473-
<!-- /ko -->
460+
<!-- ko if: $parents[0].imageButtonShowLoading -->
461+
i.icon.notched.circle.loading( data-bind = " css: { 'loadingGetResponse': $parents[0].imageLoadingGetResponse, 'conetResponse': $parents[0].imageConetResponse }")
462+
<!-- /ko -->
474463

475-
<!-- ko ifnot: $parents[0].searchSimilarImagesList().length -->
476-
.ifHaveNotSearchSimilarImagesList
477-
a.ui( data-bind = "text: infoDefine[ $root.languageIndex() ].coSearch.similarImages, click: $parents[0].requestSimilarImagesClick " )
478-
<!-- /ko -->
464+
<!-- ko if: $parents[0].imageItemsArray() && $parents[0].imageItemsArray().length -->
465+
i.icon.file.image.outline.orange.link( data-bind = "click: function () { $parents[0].imageButtonClick ( $parents[0] )}")
479466
<!-- /ko -->
467+
468+
a.ui( data-bind = " text: infoDefine[ $root.languageIndex() ].coSearch.similarImages, click: function () { $parents[0].imageButtonClick( $parents[0] )}" )
469+
480470
<!-- /ko -->
481471

482-
<!-- ko if: $parents[0].showSimilarImagesError -->
472+
<!-- ko if: $parents[0].imageButtonShowError -->
483473
span
484-
i.icon.info.circle.red.link( data-bind = "click: $parents[0].SimilarImagesErrorClick" )
485-
a.ui( data-bind = "text: messageBoxDefine [ similarImagesErrorIndex()] [ $root.languageIndex() ], click: $parents[0].SimilarImagesErrorClick "
474+
i.icon.info.circle.red.link( data-bind = "click: function () { $parents[0].imageButtonClick( $parents[0] )}" )
475+
a.ui( data-bind = "text: messageBoxDefine [ $parents[0].imageButtonErrorIndex()][ $root.languageIndex() ], click: function () { $parents[0].imageButtonClick( $parents[0] )} "
486476
style = "color: #990000a8!important;")
487477
<!-- /ko -->
488478

0 commit comments

Comments
 (0)