               [:a {:href "#" :on-click #(remove-issuer-from-favourites id state nil)} [:i {:class "fa fa-bookmark"}] (str " " (t :badge/Removefromfavourites))]
               )]]]]])))
 
+(defn issuer-filter-grid [show-favourites-atom state]
+  [:div#grid-filter {:class "form-horizontal" :style {:margin-bottom "10px"}}
+   [:div {:class "form-group wishlist-buttons"}
+       #_[:label {:for   "input-email-notifications"
+            :class "col-md-2"}
+    (str (t :core/Show) ":")]
+    [:div.col-md-10
+    [:div.buttons
+     [:button {:class (str "btn btn-default " (if-not @show-favourites-atom "btn-active"))
+               :id "btn-all"
+               :on-click #(reset! show-favourites-atom (if @show-favourites-atom false true))}
+      (t :core/All)]
+     [:button {:class (str "btn btn-default " (if @show-favourites-atom "btn-active"))
+               :id "btn-all"
+               :on-click #(reset! show-favourites-atom (if @show-favourites-atom false true))}
+      [:i {:class "fa fa-bookmark"}] (str " " (t :extra-application/Favourites))]]]]
+   [:div {:style {:margin-top "5px"}}
+    [text-field :issuer  nil "search issuer" state]]])
+
+(defn favourites-block [favourites state]
+  (if-not (empty? @favourites)
+    [:div
+     (doall
+       (for [app @favourites
+             :let [{:keys [issuer_content_name issuer_image issuer_content_url issuer_content_id]} app
+                   applications-count (issuer-applications-count issuer_content_name state)
+                   ;testing
+                   banner (if (even? (count issuer_content_name)) true false)]]
+         [:a { :key issuer_content_id
+               :data-dismiss "modal"
+               :on-click #(do
+                            (.preventDefault %)
+                            (init-issuer-connection issuer_content_id state)
+                            (swap! state assoc :show-issuer-info true
+                                   :issuer-content {:id issuer_content_id :name issuer_content_name :image issuer_image :url issuer_content_url :banner banner})
+                            (issuer-applications issuer_content_name state))}
+
+          [:div {:style {:padding "5px"}} (if issuer_image
+                                            [:img.badge-icon {:style {:width "30px" :padding-right "10px"} :src (str "/" issuer_image)}])
+           (str issuer_content_name "  ("  applications-count ")")]]
+
+         ))]
+    [:div]))
+
+(defn issuer-block [applications state]
+  (into
+    [:div
+     [:a {:data-dismiss "modal"
+          :on-click #(do
+                       (swap! state assoc :show-issuer-info false :issuer-content {:name (t :core/All)})
+                       (issuer-applications "" state))} [:div.all (t :core/All)]]]
+    (doall
+      (for [app (sort-by :issuer_content_name (distinct-by :issuer_content_name @applications))
+            :let [{:keys [issuer_content_name issuer_image issuer_content_url issuer_content_id]} app
+                  applications-count (issuer-applications-count issuer_content_name state)
+                  ;testing
+                  banner (if (even? (count issuer_content_name)) true false)]]
+        ^{:key app}[:a { :data-dismiss "modal"
+              :on-click #(do
+                           (.preventDefault %)
+                           (init-issuer-connection issuer_content_id state)
+                           (swap! state assoc :show-issuer-info true
+                                  :issuer-content {:id issuer_content_id :name issuer_content_name :image issuer_image :url issuer_content_url :banner banner})
+                           (issuer-applications issuer_content_name state))}
+
+         [:div {:style {:padding "5px"}} (if issuer_image
+                                           [:img.badge-icon {:style {:width "30px" :padding-right "10px"} :src (str "/" issuer_image)}])
+          (str issuer_content_name "  ("  applications-count ")")]]))))
+
 (defn issuer-content-modal [state]
   (let [applications (cursor state [:all-applications])
         issuer-name (cursor state [:issuer-content :name])
-        favourites (cursor state [:all-connections])]
+        favourites (cursor state [:favourites])
+        show-favourites-atom (cursor state [:show-favourite-issuers])]
     (fn []
       [:div#badge-content
        [:div.modal-body

                :order (trim order)
                :followed show-followed-only}
       :handler (fn [data]
                  (swap! state assoc :all-issuer-applications (:applications data) )
                  (all-connections state))})))

(defn fetch-badge-adverts [state]
  (let [{:keys [user-id country-selected name recipient-name issuer-name order tags show-followed-only]} @state]

    (subs text 1)
    text))

(defn create-favourite-list [favourites all]
 (sort-by :issuer_content_name (distinct-by :issuer_content_id (filter (fn [app] (some #(= (:id %) (:issuer_content_id app)) favourites)) all))))

(defn get-favourites [state]
  (ajax/GET
    (path-for (str "/obpv1/social/connections_issuer"))
    {:handler (fn [data]
                (swap! state assoc :favourites (create-favourite-list data (:all-applications @state)))
                )}))

(defn init-issuer-applications [state]
