From 07a4925f3b75b3561c9791ae68d424b3b87fe350 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 18 Sep 2016 01:48:41 +0200 Subject: [PATCH 1/7] Extract tags autocompletion JS to file --- app/assets/javascripts/app/pages/settings.js | 4 ++ .../app/views/tag_following_list_view.js | 23 +---------- .../javascripts/helpers/tags_autocomplete.js | 41 +++++++++++++++++++ app/assets/javascripts/main.js | 1 + app/assets/javascripts/mobile/mobile.js | 1 + .../pages/users-getting-started.js | 26 +----------- app/controllers/profiles_controller.rb | 7 +--- app/controllers/users_controller.rb | 1 + app/views/profiles/_edit_public.haml | 30 -------------- app/views/profiles/edit.mobile.haml | 6 +++ app/views/users/getting_started.mobile.haml | 26 +----------- 11 files changed, 59 insertions(+), 107 deletions(-) create mode 100644 app/assets/javascripts/helpers/tags_autocomplete.js diff --git a/app/assets/javascripts/app/pages/settings.js b/app/assets/javascripts/app/pages/settings.js index 517d17663..3b1f8f3e0 100644 --- a/app/assets/javascripts/app/pages/settings.js +++ b/app/assets/javascripts/app/pages/settings.js @@ -4,6 +4,10 @@ app.pages.Settings = Backbone.View.extend({ $(".settings-visibility").tooltip({placement: "top"}); $(".profile-visibility-hint").tooltip({placement: "top"}); $("[name='profile[public_details]']").bootstrapSwitch(); + + new Diaspora.TagsAutocomplete("#profile_tag_string", { + preFill: gon.preloads.tagsArray + }); } }); // @license-end diff --git a/app/assets/javascripts/app/views/tag_following_list_view.js b/app/assets/javascripts/app/views/tag_following_list_view.js index 0504ab270..d284f137c 100644 --- a/app/assets/javascripts/app/views/tag_following_list_view.js +++ b/app/assets/javascripts/app/views/tag_following_list_view.js @@ -1,6 +1,5 @@ // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later -//= require jquery.autoSuggest.custom app.views.TagFollowingList = app.views.Base.extend({ templateName: "tag_following_list", @@ -30,29 +29,9 @@ app.views.TagFollowingList = app.views.Base.extend({ }, setupAutoSuggest : function() { - this.$("input").autoSuggest("/tags", { - selectedItemProp: "name", - selectedValuesProp: "name", - searchObjProps: "name", - asHtmlID: "tags", - neverSubmit: true, - retrieveLimit: 10, - selectionLimit: false, - minChars: 2, - keyDelay: 200, - startText: "", - emptyText: "no_results", + new Diaspora.TagsAutocomplete(this.$("input"), { selectionAdded: _.bind(this.suggestSelection, this) }); - - this.$("input").bind('keydown', function(evt){ - if(evt.which === Keycodes.ENTER || evt.which === Keycodes.TAB || evt.which === Keycodes.SPACE) { - evt.preventDefault(); - if( $('li.as-result-item.active').length === 0 ){ - $('li.as-result-item').first().click(); - } - } - }); }, presenter : function() { diff --git a/app/assets/javascripts/helpers/tags_autocomplete.js b/app/assets/javascripts/helpers/tags_autocomplete.js new file mode 100644 index 000000000..0aefefae7 --- /dev/null +++ b/app/assets/javascripts/helpers/tags_autocomplete.js @@ -0,0 +1,41 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +Diaspora.TagsAutocomplete = function(element, opts) { + this.initialize(element, opts); +}; + +Diaspora.TagsAutocomplete.prototype = { + constructor: Diaspora.TagsAutocomplete, + + initialize: function(element, opts) { + this.options = { + selectedItemProp: "name", + selectedValuesProp: "name", + searchObjProps: "name", + asHtmlID: "tags", + neverSubmit: true, + retrieveLimit: 10, + selectionLimit: false, + minChars: 2, + keyDelay: 200, + startText: "", + emptyText: Diaspora.I18n.t("no_results") + }; + + $.extend(this.options, opts); + + this.autocompleteInput = $(element); + this.autocompleteInput.autoSuggest("/tags", this.options); + this.autocompleteInput.bind("keydown", this.keydown); + }, + + keydown: function(evt) { + if (evt.which === Keycodes.ENTER || evt.which === Keycodes.TAB || evt.which === Keycodes.SPACE) { + evt.preventDefault(); + if ($("li.as-result-item.active").length === 0) { + $("li.as-result-item").first().click(); + } + } + } +}; +// @license-end diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index 36667eb55..1d1390820 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -17,6 +17,7 @@ //= require jquery-ui/mouse //= require jquery-ui/sortable //= require keycodes +//= require jquery.autoSuggest.custom //= require fileuploader-custom //= require handlebars.runtime //= require posix-bracket-expressions diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index fad57b3f0..1cb4b5b2e 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -16,6 +16,7 @@ //= require bootstrap //= require diaspora //= require helpers/i18n +//= require helpers/tags_autocomplete //= require widgets/timeago //= require mobile/mobile_application //= require mobile/mobile_file_uploader diff --git a/app/assets/javascripts/pages/users-getting-started.js b/app/assets/javascripts/pages/users-getting-started.js index cb82e03a0..00ec09f05 100644 --- a/app/assets/javascripts/pages/users-getting-started.js +++ b/app/assets/javascripts/pages/users-getting-started.js @@ -49,36 +49,14 @@ Diaspora.Pages.UsersGettingStarted = function() { return confirmation; }); - /* ------ */ - var autocompleteInput = $("#follow_tags"); var tagFollowings = new app.collections.TagFollowings(); - - autocompleteInput.autoSuggest("/tags", { - selectedItemProp: "name", - selectedValuesProp: "name", - searchObjProps: "name", - asHtmlID: "tags", - neverSubmit: true, - retrieveLimit: 10, - selectionLimit: false, - minChars: 2, - keyDelay: 200, - startText: "", - emptyText: "no_results", + new Diaspora.TagsAutocomplete("#follow_tags", { + preFill: gon.preloads.tagsArray, selectionAdded: function(elem){tagFollowings.create({"name":$(elem[0]).text().substring(2)})}, selectionRemoved: function(elem){ tagFollowings.where({"name":$(elem[0]).text().substring(2)})[0].destroy(); elem.remove(); } - }); - - autocompleteInput.bind('keydown', function(evt){ - if(evt.which === Keycodes.ENTER || evt.which === Keycodes.TAB || evt.which === Keycodes.SPACE) { - evt.preventDefault(); - if( $('li.as-result-item.active').length === 0 ){ - $('li.as-result-item').first().click(); - } - } }); }); }; diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 409dcaee0..bb4d9b070 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -23,12 +23,7 @@ class ProfilesController < ApplicationController @aspect = :person_edit @profile = @person.profile - @tags = @profile.tags - @tags_array = [] - @tags.each do |obj| - @tags_array << { :name => ("#"+obj.name), - :value => ("#"+obj.name)} - end + gon.preloads[:tagsArray] = @profile.tags.map {|tag| {name: "##{tag.name}", value: "##{tag.name}"} } end def update diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 63d8074e1..b13dd822c 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -87,6 +87,7 @@ class UsersController < ApplicationController @person = @user.person @profile = @user.profile gon.preloads[:inviter] = PersonPresenter.new(current_user.invited_by.try(:person), current_user).as_json + gon.preloads[:tagsArray] = current_user.followed_tags.map {|tag| {name: "##{tag.name}", value: "##{tag.name}"} } render "users/getting_started" end diff --git a/app/views/profiles/_edit_public.haml b/app/views/profiles/_edit_public.haml index 74411cae7..c03c1b23f 100644 --- a/app/views/profiles/_edit_public.haml +++ b/app/views/profiles/_edit_public.haml @@ -1,33 +1,3 @@ -- content_for :head do - :javascript - $(document).ready(function () { - var data = $.parseJSON( '#{@tags_array.to_json.gsub("'", "\\\\'")}' ), - autocompleteInput = $("#profile_tag_string"); - - autocompleteInput.autoSuggest("#{tags_path}", { - selectedItemProp: "name", - selectedValuesProp: "name", - searchObjProps: "name", - asHtmlID: "tags", - neverSubmit: true, - retrieveLimit: 10, - minChars: 2, - keyDelay: 200, - startText: "", - emptyText: "#{t('no_results')}", - preFill: data - }); - - autocompleteInput.bind('keydown', function(evt){ - if(evt.which === Keycodes.ENTER || evt.which === Keycodes.TAB || evt.which === Keycodes.SPACE) { - evt.preventDefault(); - if( $('li.as-result-item.active').length == 0 ){ - $('li.as-result-item').first().click(); - } - } - }); - }); - %h3.inline = t("profiles.edit.basic") %span{ :title => t("profiles.edit.basic_hint") } diff --git a/app/views/profiles/edit.mobile.haml b/app/views/profiles/edit.mobile.haml index 608b9a8c0..98aa81533 100644 --- a/app/views/profiles/edit.mobile.haml +++ b/app/views/profiles/edit.mobile.haml @@ -2,6 +2,12 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. +- content_for :head do + :javascript + $(document).ready(function () { + new Diaspora.TagsAutocomplete("#profile_tag_string", {preFill: gon.preloads.tagsArray}); + }); + .settings_container.container-fluid .row .col-md-12 diff --git a/app/views/users/getting_started.mobile.haml b/app/views/users/getting_started.mobile.haml index ff158e90a..65c56a70a 100644 --- a/app/views/users/getting_started.mobile.haml +++ b/app/views/users/getting_started.mobile.haml @@ -5,31 +5,7 @@ - content_for :head do :javascript $(document).ready(function () { - var data = $.parseJSON( '#{@tags_array.to_json.gsub("'", "\\\\'")}' ), - autocompleteInput = $("#follow_tags"); - - autocompleteInput.autoSuggest("#{tags_path}", { - selectedItemProp: "name", - selectedValuesProp: "name", - searchObjProps: "name", - asHtmlID: "tags", - neverSubmit: true, - retrieveLimit: 10, - minChars: 2, - keyDelay: 200, - startText: "", - emptyText: "#{t('no_results')}", - preFill: data - }); - - autocompleteInput.bind('keydown', function(evt){ - if(evt.which === Keycodes.ENTER || evt.which === Keycodes.TAB || evt.which === Keycodes.SPACE) { - evt.preventDefault(); - if( $('li.as-result-item.active').length == 0 ){ - $('li.as-result-item').first().click(); - } - } - }); + new Diaspora.TagsAutocomplete("#follow_tags"); }); :css From 14304f3620f6441353d8c298715431e4fcf74728 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Sun, 18 Sep 2016 03:03:53 +0200 Subject: [PATCH 2/7] Extract profile photo uploader to file --- app/assets/javascripts/app/pages/settings.js | 1 + .../helpers/profile_photo_uploader.js | 61 +++++++++++++++++++ app/assets/javascripts/mobile/mobile.js | 1 + .../pages/users-getting-started.js | 1 + app/views/photos/_new_profile_photo.haml | 56 ----------------- app/views/profiles/edit.mobile.haml | 1 + app/views/users/getting_started.mobile.haml | 1 + config/locales/diaspora/en.yml | 4 -- 8 files changed, 66 insertions(+), 60 deletions(-) create mode 100644 app/assets/javascripts/helpers/profile_photo_uploader.js diff --git a/app/assets/javascripts/app/pages/settings.js b/app/assets/javascripts/app/pages/settings.js index 3b1f8f3e0..725abbedc 100644 --- a/app/assets/javascripts/app/pages/settings.js +++ b/app/assets/javascripts/app/pages/settings.js @@ -8,6 +8,7 @@ app.pages.Settings = Backbone.View.extend({ new Diaspora.TagsAutocomplete("#profile_tag_string", { preFill: gon.preloads.tagsArray }); + new Diaspora.ProfilePhotoUploader(); } }); // @license-end diff --git a/app/assets/javascripts/helpers/profile_photo_uploader.js b/app/assets/javascripts/helpers/profile_photo_uploader.js new file mode 100644 index 000000000..c50bc5021 --- /dev/null +++ b/app/assets/javascripts/helpers/profile_photo_uploader.js @@ -0,0 +1,61 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +Diaspora.ProfilePhotoUploader = function() { + this.initialize(); +}; + +Diaspora.ProfilePhotoUploader.prototype = { + constructor: Diaspora.ProfilePhotoUploader, + + initialize: function() { + new qq.FileUploaderBasic({ + element: document.getElementById("file-upload"), + params: {"photo": {"pending": true, "aspect_ids": "all", "set_profile_photo": true}}, + allowedExtensions: ["jpg", "jpeg", "png"], + action: "/photos", + button: document.getElementById("file-upload"), + sizeLimit: 4194304, + + onProgress: function(id, fileName, loaded, total) { + var progress = Math.round(loaded / total * 100); + $("#fileInfo").text(fileName + " " + progress + "%"); + }, + + messages: { + typeError: Diaspora.I18n.t("photo_uploader.invalid_ext"), + sizeError: Diaspora.I18n.t("photo_uploader.size_error"), + emptyError: Diaspora.I18n.t("photo_uploader.empty") + }, + + onSubmit: function() { + $("#file-upload").addClass("loading"); + $("#profile_photo_upload").find(".avatar").addClass("loading"); + $("#file-upload-spinner").removeClass("hidden"); + $("#fileInfo").show(); + }, + + onComplete: function(_id, fileName, responseJSON) { + $("#file-upload-spinner").addClass("hidden"); + $("#fileInfo").text(Diaspora.I18n.t("photo_uploader.completed", {"file": fileName})); + $("#file-upload").removeClass("loading"); + + /* flash message prompt */ + var message = Diaspora.I18n.t("photo_uploader.looking_good"); + if (app.flashMessages) { app.flashMessages.success(message); } + + var id = responseJSON.data.photo.id; + var url = responseJSON.data.photo.unprocessed_image.url; + var oldPhoto = $("#photo_id"); + if (oldPhoto.length === 0) { + $("#update_profile_form").prepend(""); + } else { + oldPhoto.val(id); + } + + $("#profile_photo_upload").find(".avatar").removeClass("loading"); + $("#profile_photo_upload").find(".avatar").attr("src", url); + } + }); + } +}; +// @license-end diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index 1cb4b5b2e..46c013538 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -16,6 +16,7 @@ //= require bootstrap //= require diaspora //= require helpers/i18n +//= require helpers/profile_photo_uploader //= require helpers/tags_autocomplete //= require widgets/timeago //= require mobile/mobile_application diff --git a/app/assets/javascripts/pages/users-getting-started.js b/app/assets/javascripts/pages/users-getting-started.js index 00ec09f05..b70951422 100644 --- a/app/assets/javascripts/pages/users-getting-started.js +++ b/app/assets/javascripts/pages/users-getting-started.js @@ -58,6 +58,7 @@ Diaspora.Pages.UsersGettingStarted = function() { elem.remove(); } }); + new Diaspora.ProfilePhotoUploader(); }); }; // @license-end diff --git a/app/views/photos/_new_profile_photo.haml b/app/views/photos/_new_profile_photo.haml index 585028add..f5cb61659 100644 --- a/app/views/photos/_new_profile_photo.haml +++ b/app/views/photos/_new_profile_photo.haml @@ -2,62 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. - -- content_for :head do - :javascript - function createUploader(){ - var uploader = new qq.FileUploaderBasic({ - element: document.getElementById('file-upload'), - params: {'photo' : {'pending' : true, 'aspect_ids' : "all", 'set_profile_photo': true}}, - allowedExtensions: ['jpg', 'jpeg', 'png'], - action: "#{photos_path}", - button: document.getElementById('file-upload'), - sizeLimit: 4194304, - - onProgress: function(id, fileName, loaded, total){ - var progress = Math.round(loaded / total * 100 ); - $('#fileInfo').text(fileName + ' ' + progress + '%'); - }, - - messages: { - typeError: "#{t('photos.new_photo.invalid_ext')}", - sizeError: "#{t('photos.new_photo.size_error')}", - emptyError: "#{t('photos.new_photo.empty')}" - }, - - onSubmit: function(id, fileName){ - $('#file-upload').addClass("loading"); - $("#profile_photo_upload").find(".avatar").addClass('loading'); - $("#file-upload-spinner").removeClass("hidden"); - $("#fileInfo").show(); - }, - - onComplete: function(id, fileName, responseJSON){ - $("#file-upload-spinner").addClass("hidden"); - $("#fileInfo").text(Diaspora.I18n.t("photo_uploader.completed", {"file": fileName})); - $('#file-upload').removeClass("loading"); - - /* flash message prompt */ - var message = Diaspora.I18n.t("photo_uploader.looking_good"); - if(app.flashMessages) { app.flashMessages.success(message); } - - var id = responseJSON.data.photo.id; - var url = responseJSON.data.photo.unprocessed_image.url; - var oldPhoto = $('#photo_id'); - if(oldPhoto.length == 0) { - $('#update_profile_form').prepend(""); - } else { - oldPhoto.val(id); - } - - $("#profile_photo_upload").find(".avatar").removeClass('loading'); - $("#profile_photo_upload").find(".avatar").attr("src",url); - $(".avatar[data-person_id=#{current_user.person.id}]").attr("src",url); - } - }); - } - window.onload = createUploader; - .profile-photo-upload#profile_photo_upload = owner_image_tag(:thumb_large) .small-horizontal-spacer diff --git a/app/views/profiles/edit.mobile.haml b/app/views/profiles/edit.mobile.haml index 98aa81533..eecb0889a 100644 --- a/app/views/profiles/edit.mobile.haml +++ b/app/views/profiles/edit.mobile.haml @@ -6,6 +6,7 @@ :javascript $(document).ready(function () { new Diaspora.TagsAutocomplete("#profile_tag_string", {preFill: gon.preloads.tagsArray}); + new Diaspora.ProfilePhotoUploader(); }); .settings_container.container-fluid diff --git a/app/views/users/getting_started.mobile.haml b/app/views/users/getting_started.mobile.haml index 65c56a70a..e9e372cab 100644 --- a/app/views/users/getting_started.mobile.haml +++ b/app/views/users/getting_started.mobile.haml @@ -6,6 +6,7 @@ :javascript $(document).ready(function () { new Diaspora.TagsAutocomplete("#follow_tags"); + new Diaspora.ProfilePhotoUploader(); }); :css diff --git a/config/locales/diaspora/en.yml b/config/locales/diaspora/en.yml index 0f94fa9fc..f98d9e467 100644 --- a/config/locales/diaspora/en.yml +++ b/config/locales/diaspora/en.yml @@ -901,10 +901,6 @@ en: type_error: "Photo upload failed. Are you sure an image was added?" destroy: notice: "Photo deleted." - new_photo: - invalid_ext: "{file} has invalid extension. Only {extensions} are allowed." - size_error: "{file} is too large, maximum file size is {sizeLimit}." - empty: "{file} is empty, please select files again without it." new_profile_photo: upload: "Upload a new profile photo!" From b8c76a331759422b5f6f670842dabf6548f40700 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 19 Sep 2016 00:12:38 +0200 Subject: [PATCH 3/7] Trigger getting started with backbone --- .../javascripts/app/views/publisher/getting_started_view.js | 1 - app/assets/javascripts/app/views/publisher_view.js | 6 +++++- app/controllers/streams_controller.rb | 3 ++- app/helpers/interim_stream_hackiness_helper.rb | 6 +----- app/views/publisher/_publisher.html.haml | 6 ------ lib/publisher.rb | 3 +-- lib/stream/multi.rb | 3 ++- spec/lib/publisher_spec.rb | 2 +- spec/lib/stream/multi_spec.rb | 2 +- 9 files changed, 13 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/app/views/publisher/getting_started_view.js b/app/assets/javascripts/app/views/publisher/getting_started_view.js index 5ba089efc..02a025e0a 100644 --- a/app/assets/javascripts/app/views/publisher/getting_started_view.js +++ b/app/assets/javascripts/app/views/publisher/getting_started_view.js @@ -18,7 +18,6 @@ app.views.PublisherGettingStarted = Backbone.View.extend({ // initiate all the popover message boxes show: function() { - app.publisher.open(); this._addPopover(this.firstMessage, { trigger: "manual", id: "first_message_explain", diff --git a/app/assets/javascripts/app/views/publisher_view.js b/app/assets/javascripts/app/views/publisher_view.js index 1b9f2f56c..de9245027 100644 --- a/app/assets/javascripts/app/views/publisher_view.js +++ b/app/assets/javascripts/app/views/publisher_view.js @@ -91,6 +91,7 @@ app.views.Publisher = Backbone.View.extend({ this.initSubviews(); this.checkSubmitAvailability(); + this.triggerGettingStarted(); return this; }, @@ -184,7 +185,10 @@ app.views.Publisher = Backbone.View.extend({ // show the "getting started" popups around the publisher triggerGettingStarted: function() { - this.viewGettingStarted.show(); + if (gon.preloads.getting_started) { + this.open(); + this.viewGettingStarted.show(); + } }, createStatusMessage : function(evt) { diff --git a/app/controllers/streams_controller.rb b/app/controllers/streams_controller.rb index f8e8b422f..18ec1837f 100644 --- a/app/controllers/streams_controller.rb +++ b/app/controllers/streams_controller.rb @@ -28,7 +28,8 @@ class StreamsController < ApplicationController end def multi - stream_responder(Stream::Multi) + gon.preloads[:getting_started] = current_user.getting_started + stream_responder(Stream::Multi) end def commented diff --git a/app/helpers/interim_stream_hackiness_helper.rb b/app/helpers/interim_stream_hackiness_helper.rb index 4219d29fe..c5d6992ab 100644 --- a/app/helpers/interim_stream_hackiness_helper.rb +++ b/app/helpers/interim_stream_hackiness_helper.rb @@ -25,7 +25,7 @@ module InterimStreamHackinessHelper if params[:prefill].present? params[:prefill] elsif defined?(@stream) - @stream.publisher.prefill + @stream.publisher.prefill else nil end @@ -50,8 +50,4 @@ module InterimStreamHackinessHelper def publisher_public publisher_method(:public) end - - def publisher_explain - publisher_method(:explain) - end end diff --git a/app/views/publisher/_publisher.html.haml b/app/views/publisher/_publisher.html.haml index 4d85b0290..5e1ca38f1 100644 --- a/app/views/publisher/_publisher.html.haml +++ b/app/views/publisher/_publisher.html.haml @@ -1,9 +1,3 @@ --if publisher_explain - :javascript - $(document).ready(function() { - if( app.publisher ) app.publisher.triggerGettingStarted(); - }); - .row.publisher#publisher{class: ((aspect == :profile || publisher_open) ? "mention_popup" : "closed")} .content_creation = form_for(StatusMessage.new) do |status| diff --git a/lib/publisher.rb b/lib/publisher.rb index 71894b652..677afb89f 100644 --- a/lib/publisher.rb +++ b/lib/publisher.rb @@ -1,12 +1,11 @@ class Publisher - attr_accessor :user, :open, :prefill, :public, :explain + attr_accessor :user, :open, :prefill, :public def initialize(user, opts={}) self.user = user self.open = opts[:open] self.prefill = opts[:prefill] self.public = opts[:public] - self.explain = opts[:explain] end def text diff --git a/lib/stream/multi.rb b/lib/stream/multi.rb index 995804372..868a82228 100644 --- a/lib/stream/multi.rb +++ b/lib/stream/multi.rb @@ -23,9 +23,10 @@ class Stream::Multi < Stream::Base end private + def publisher_opts if welcome? - {open: true, prefill: publisher_prefill, public: true, explain: true} + {open: true, prefill: publisher_prefill, public: true} else super end diff --git a/spec/lib/publisher_spec.rb b/spec/lib/publisher_spec.rb index 0094f8f49..abbd5ab5b 100644 --- a/spec/lib/publisher_spec.rb +++ b/spec/lib/publisher_spec.rb @@ -23,7 +23,7 @@ describe Publisher do end end - ["open", "public", "explain"].each do |property| + %w(open public).each do |property| describe "##{property}" do it 'defaults to closed' do expect(@publisher.send("#{property}".to_sym)).to be_falsey diff --git a/spec/lib/stream/multi_spec.rb b/spec/lib/stream/multi_spec.rb index 5c1df2468..8f84caf54 100644 --- a/spec/lib/stream/multi_spec.rb +++ b/spec/lib/stream/multi_spec.rb @@ -26,7 +26,7 @@ describe Stream::Multi do prefill_text = "sup?" allow(@stream).to receive(:welcome?).and_return(true) allow(@stream).to receive(:publisher_prefill).and_return(prefill_text) - expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true, explain: true) + expect(@stream.send(:publisher_opts)).to eq(open: true, prefill: prefill_text, public: true) end it 'provides no opts if welcome? is not set' do From 459ebffa6ebaa30a01c2d7edc653764f8cf60e09 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 19 Sep 2016 01:23:37 +0200 Subject: [PATCH 4/7] Start background search with gon --- app/assets/javascripts/contact-list.js | 6 ++++++ app/controllers/people_controller.rb | 13 ++++++++----- app/views/people/index.html.haml | 14 +++----------- 3 files changed, 17 insertions(+), 16 deletions(-) diff --git a/app/assets/javascripts/contact-list.js b/app/assets/javascripts/contact-list.js index 3dfa85dc5..87740a64a 100644 --- a/app/assets/javascripts/contact-list.js +++ b/app/assets/javascripts/contact-list.js @@ -30,4 +30,10 @@ var List = { setTimeout( "List.runDelayedSearch('" + theSearch + "')", 10000); } }; + +$(document).ready(function() { + if (gon.preloads.background_query) { + List.startSearchDelay(gon.preloads.background_query); + } +}); // @license-end diff --git a/app/controllers/people_controller.rb b/app/controllers/people_controller.rb index 303423aa8..930ed0b7c 100644 --- a/app/controllers/people_controller.rb +++ b/app/controllers/people_controller.rb @@ -39,13 +39,10 @@ class PeopleController < ApplicationController end format.any(:html, :mobile) do - #only do it if it is an email address + # only do it if it is a diaspora*-ID if diaspora_id?(search_query) @people = Person.where(diaspora_handle: search_query.downcase, closed_account: false) - if @people.empty? - Workers::FetchWebfinger.perform_async(search_query) - @background_query = search_query.downcase - end + background_search(search_query) if @people.empty? end @people = @people.paginate(:page => params[:page], :per_page => 15) @hashes = hashes_for_people(@people, @aspects) @@ -167,6 +164,12 @@ class PeopleController < ApplicationController raise Diaspora::AccountClosed if @person.closed_account? end + def background_search(search_query) + Workers::FetchWebfinger.perform_async(search_query) + @background_query = search_query.downcase + gon.preloads[:background_query] = @background_query + end + def hashes_for_people(people, aspects) people.map {|person| { diff --git a/app/views/people/index.html.haml b/app/views/people/index.html.haml index 5dd55ddbf..a3c19c069 100644 --- a/app/views/people/index.html.haml +++ b/app/views/people/index.html.haml @@ -16,20 +16,12 @@ .col-md-8 #people_stream.stream - if @hashes.empty? - - if @background_query.present? - - / TODO this is gross, and should be extracted! - :javascript - $(document).ready( function() { - List.startSearchDelay('#{@background_query}') - } ); - - %p + %p + - if @background_query.present? = t(".searching") .loader .spinner - - else - %p + - else = t('.no_one_found') - else - for hash in @hashes From fccabf9983c0792d55cf7c86862b7a3770f8d1e0 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 19 Sep 2016 02:19:38 +0200 Subject: [PATCH 5/7] Extract mobile bookmarklet JS to file --- app/assets/javascripts/mobile/bookmarklet.js | 21 +++++++++++++++++++ .../status_messages/bookmarklet.mobile.haml | 16 +------------- config/application.rb | 1 + 3 files changed, 23 insertions(+), 15 deletions(-) create mode 100644 app/assets/javascripts/mobile/bookmarklet.js diff --git a/app/assets/javascripts/mobile/bookmarklet.js b/app/assets/javascripts/mobile/bookmarklet.js new file mode 100644 index 000000000..94822c2ef --- /dev/null +++ b/app/assets/javascripts/mobile/bookmarklet.js @@ -0,0 +1,21 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +$(document).ready(function() { + function publisherContent(params) { + if (params.content) { + return params.content; + } + + var content = params.title + " - " + params.url; + if (params.notes.length > 0) { + content += " - " + params.notes; + } + return content; + } + + var content = publisherContent(gon.preloads.bookmarklet); + if (content.length > 0) { + $("#status_message_text").val(content); + } +}); +// @license-end diff --git a/app/views/status_messages/bookmarklet.mobile.haml b/app/views/status_messages/bookmarklet.mobile.haml index e6c6227c2..0dafbc991 100644 --- a/app/views/status_messages/bookmarklet.mobile.haml +++ b/app/views/status_messages/bookmarklet.mobile.haml @@ -4,18 +4,4 @@ = render :partial => 'publisher/publisher', :locals => { :aspect => :profile, :selected_aspects => @aspects, :aspect_ids => @aspect_ids } -:javascript - var contents = "#{escape_javascript params[:content]}"; - if(!contents){ - contents = "#{escape_javascript params[:title]} - #{escape_javascript params[:url]}"; - var notes = "#{escape_javascript params[:notes]}"; - if (notes.length > 0){ - contents += " - " + notes; - } - } - - $(document).ready(function() { - if (contents.length > 0) { - $("#status_message_text").val(contents); - } - }); += javascript_include_tag "mobile/bookmarklet" diff --git a/config/application.rb b/config/application.rb index ca30da275..1e5e33cbf 100644 --- a/config/application.rb +++ b/config/application.rb @@ -75,6 +75,7 @@ module Diaspora jquery-textchange.js main.js jsxc.js + mobile/bookmarklet.js mobile/mobile.js people.js publisher.js From be33b425ba2fe0a599e6522eef17be543746cff2 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Mon, 19 Sep 2016 02:52:15 +0200 Subject: [PATCH 6/7] remove unused precompiled JS files --- config/application.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/config/application.rb b/config/application.rb index 1e5e33cbf..4f8668eeb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -65,29 +65,24 @@ module Diaspora config.assets.initialize_on_precompile = false # Precompile additional assets (application.js, application.css, and all non-JS/CSS are already added) - config.assets.precompile += %w{ - aspect-contacts.js + config.assets.precompile += %w( contact-list.js ie.js inbox.js jquery2.js jquery_ujs.js - jquery-textchange.js main.js jsxc.js mobile/bookmarklet.js mobile/mobile.js - people.js - publisher.js templates.js - validation.js error_pages.css admin.css rtl.css color_themes/*/desktop.css color_themes/*/mobile.css - } + ) # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' From caf46fdcb91d6be1b2ea6df660050bd475bbbc51 Mon Sep 17 00:00:00 2001 From: Benjamin Neff Date: Wed, 21 Sep 2016 01:01:40 +0200 Subject: [PATCH 7/7] Move initialization of mobile profile edit functions to file closes #7113 --- Changelog.md | 1 + app/assets/javascripts/mobile/mobile.js | 1 + app/assets/javascripts/mobile/mobile_profile_edit.js | 12 ++++++++++++ app/views/profiles/edit.mobile.haml | 7 ------- app/views/users/getting_started.mobile.haml | 7 ------- 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 app/assets/javascripts/mobile/mobile_profile_edit.js diff --git a/Changelog.md b/Changelog.md index 8f49e58ba..280fe21cd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -13,6 +13,7 @@ Note: Although this is a minor release, the configuration file changed because t * Use translation for NodeInfo services [#7102](https://github.com/diaspora/diaspora/pull/7102) * Adopt new Mapbox tile URIs [#7066](https://github.com/diaspora/diaspora/pull/7066) * Refactored post interactions on the single post view [#7089](https://github.com/diaspora/diaspora/pull/7089) +* Extract inline JavaScript [#7113](https://github.com/diaspora/diaspora/pull/7113) ## Bug fixes * Post comments no longer get collapsed when interacting with a post [#7040](https://github.com/diaspora/diaspora/pull/7040) diff --git a/app/assets/javascripts/mobile/mobile.js b/app/assets/javascripts/mobile/mobile.js index 46c013538..f7f7a2a45 100644 --- a/app/assets/javascripts/mobile/mobile.js +++ b/app/assets/javascripts/mobile/mobile.js @@ -21,6 +21,7 @@ //= require widgets/timeago //= require mobile/mobile_application //= require mobile/mobile_file_uploader +//= require mobile/mobile_profile_edit //= require mobile/profile_aspects //= require mobile/tag_following //= require mobile/publisher diff --git a/app/assets/javascripts/mobile/mobile_profile_edit.js b/app/assets/javascripts/mobile/mobile_profile_edit.js new file mode 100644 index 000000000..0dae9aae3 --- /dev/null +++ b/app/assets/javascripts/mobile/mobile_profile_edit.js @@ -0,0 +1,12 @@ +// @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-v3-or-Later + +$(document).ready(function() { + if (Diaspora.Page === "ProfilesEdit") { + new Diaspora.TagsAutocomplete("#profile_tag_string", {preFill: gon.preloads.tagsArray}); + new Diaspora.ProfilePhotoUploader(); + } else if (Diaspora.Page === "UsersGettingStarted") { + new Diaspora.TagsAutocomplete("#follow_tags", {preFill: gon.preloads.tagsArray}); + new Diaspora.ProfilePhotoUploader(); + } +}); +// @license-end diff --git a/app/views/profiles/edit.mobile.haml b/app/views/profiles/edit.mobile.haml index eecb0889a..608b9a8c0 100644 --- a/app/views/profiles/edit.mobile.haml +++ b/app/views/profiles/edit.mobile.haml @@ -2,13 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -- content_for :head do - :javascript - $(document).ready(function () { - new Diaspora.TagsAutocomplete("#profile_tag_string", {preFill: gon.preloads.tagsArray}); - new Diaspora.ProfilePhotoUploader(); - }); - .settings_container.container-fluid .row .col-md-12 diff --git a/app/views/users/getting_started.mobile.haml b/app/views/users/getting_started.mobile.haml index e9e372cab..91dfcc161 100644 --- a/app/views/users/getting_started.mobile.haml +++ b/app/views/users/getting_started.mobile.haml @@ -2,13 +2,6 @@ -# licensed under the Affero General Public License version 3 or later. See -# the COPYRIGHT file. -- content_for :head do - :javascript - $(document).ready(function () { - new Diaspora.TagsAutocomplete("#follow_tags"); - new Diaspora.ProfilePhotoUploader(); - }); - :css .media, .bd{ overflow: visible;}