Browse Source

Added regrouping

master
Igor Zhukov 9 years ago
parent
commit
5f1f7d7846
  1. 5
      app/js/directives.js
  2. 79
      app/js/services.js
  3. 9
      app/less/app.less
  4. 8
      app/partials/desktop/inline_results.html

5
app/js/directives.js

@ -1430,7 +1430,7 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -1430,7 +1430,7 @@ angular.module('myApp.directives', ['myApp.filters'])
})
.directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, shouldFocusOnInteraction) {
.directive('mySendForm', function (_, $timeout, $compile, $modalStack, $http, $interpolate, Storage, AppStickersManager, AppDocsManager, ErrorService, AppInlineBotsManager, shouldFocusOnInteraction) {
return {
link: link,
scope: {
@ -1534,6 +1534,9 @@ angular.module('myApp.directives', ['myApp.filters']) @@ -1534,6 +1534,9 @@ angular.module('myApp.directives', ['myApp.filters'])
});
$scope.$on('inline_results', function (e, inlineResults) {
var w = 180;
var h = 50;
AppInlineBotsManager.regroupWrappedResults(inlineResults.results, w, h);
setZeroTimeout(function () {
composer.showInlineSuggestions(inlineResults);
});

79
app/js/services.js

@ -2600,6 +2600,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2600,6 +2600,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
return {
sendInlineResult: sendInlineResult,
regroupWrappedResults: regroupWrappedResults,
getInlineResults: getInlineResults
};
@ -2613,6 +2614,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2613,6 +2614,7 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
delete botResults._;
delete botResults.flags;
delete botResults.query_id;
angular.forEach(botResults.results, function (result) {
var qID = queryID + '_' + result.id;
result.qID = qID;
@ -2622,10 +2624,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2622,10 +2624,10 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
result.rDescription = RichTextProcessor.wrapRichText(result.description, {noLinebreaks: true, noLinks: true});
result.initials = (result.url || result.title || result.type || '').substr(0, 1)
if (result._ == 'botInlineMediaResultDocument') {
if (result.document) {
AppDocsManager.saveDoc(result.document);
}
else if (result._ == 'botInlineMediaResultPhoto') {
if (result.photo) {
AppPhotosManager.savePhoto(result.photo);
}
@ -2635,6 +2637,79 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils']) @@ -2635,6 +2637,79 @@ angular.module('myApp.services', ['myApp.i18n', 'izhukov.utils'])
});
}
function regroupWrappedResults (results, rowW, rowH) {
if (!results ||
!results[0] ||
results[0].type != 'photo' && results[0].type != 'gif') {
return;
}
var ratios = [];
angular.forEach(results, function (result) {
var w, h;
if (result._ == 'botInlineMediaResultDocument') {
w = result.document.w;
h = result.document.h;
}
else if (result._ == 'botInlineMediaResultPhoto') {
var photoSize = (result.photo.sizes || [])[0];
w = photoSize && photoSize.w;
h = photoSize && photoSize.h;
}
else {
w = result.w;
h = result.h;
}
if (!w || !h) {
w = h = 1;
}
ratios.push(w / h);
});
var rows = [];
var curCnt = 0;
var curW = 0;
angular.forEach(ratios, function (ratio) {
var w = ratio * rowH;
curW += w;
console.log(curCnt, w, curW, rowW);
if (!curCnt || curCnt < 4 && curW < (rowW * 1.1)) {
curCnt++;
} else {
rows.push(curCnt);
curCnt = 1;
curW = w;
}
});
if (curCnt) {
rows.push(curCnt);
}
var i = 0;
var thumbs = [];
var lastRowI = rows.length - 1;
angular.forEach(rows, function (rowCnt, rowI) {
var lastRow = rowI == lastRowI;
var curRatios = ratios.slice(i, i + rowCnt);
var sumRatios = 0;
angular.forEach(curRatios, function (ratio) {
sumRatios += ratio;
});
angular.forEach(curRatios, function (ratio, j) {
var thumbH = rowH;
var thumbW = rowW * ratio / sumRatios;
var realW = thumbH * ratio;
if (lastRow && thumbW > realW) {
thumbW = realW;
}
var result = results[i + j];
result.thumbW = Math.floor(thumbW);
result.thumbH = Math.floor(thumbH);
});
i += rowCnt;
});
}
function sendInlineResult (peerID, qID, options) {
var inlineResult = inlineResults[qID];
if (inlineResult === undefined) {

9
app/less/app.less

@ -3153,7 +3153,7 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { @@ -3153,7 +3153,7 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before {
}
.inline_result_wrap {
display: block;
display: inline-block;
}
.inline_result_article {
display: block;
@ -3184,6 +3184,13 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before { @@ -3184,6 +3184,13 @@ _:-ms-lang(x), .composer_rich_textarea:empty:focus:before {
font-weight: bold;
}
.inline_result_gif {
display: inline-block;
}
.composer_dropdown > li > a.inline_result_gif {
padding: 0;
}
.error_modal_window {
.modal-dialog {

8
app/partials/desktop/inline_results.html

@ -1,5 +1,11 @@ @@ -1,5 +1,11 @@
<ul class="inline_results_wrap composer_dropdown">
<li class="inline_result_wrap" ng-repeat="result in botResults.results track by result.qID" ng-switch="result.type">
<li class="inline_result_wrap" ng-class="" ng-repeat="result in botResults.results track by result.qID" ng-switch="result.type">
<a ng-switch-when="gif" class="inline_result_gif img_gif_with_progress_wrap" data-inlineid="{{result.qID}}">
<div class="img_gif_image_wrap" ng-switch="result._">
<img ng-switch-when="botInlineMediaResultDocument" class="img_gif_thumb" my-load-thumb thumb="result.document.thumb" width="{{result.thumbW}}" height="{{result.thumbH}}" />
<img ng-switch-default ng-if="result.thumbUrl !== undefined" class="img_gif_thumb" ng- width="{{result.thumbW}}" height="{{result.thumbH}}" ng-src="{{result.thumbUrl}}" />
</div>
</a>
<a ng-switch-default class="inline_result_article clearfix" data-inlineid="{{result.qID}}">
<div class="inline_article_thumb_wrap pull-left" ng-switch="result.thumbUrl !== undefined">
<img ng-switch-when="true" class="inline_article_thumb" ng-src="{{result.thumbUrl}}"/>

Loading…
Cancel
Save