Skip to content
Snippets Groups Projects
Commit 3e2f41aa authored by Allen Gilliland's avatar Allen Gilliland
Browse files

Merge pull request #2217 from metabase/fix-unpositioned-dashcards

style tweaks.
parents cda3b61c e6f43e2a
No related branches found
No related tags found
No related merge requests found
......@@ -154,19 +154,19 @@
;; deal with dashboard cards which have NULL `:row` or `:col` values
(defmigration fix-dashboard-cards-without-positions
(let [bad-dashboards (k/select DashboardCard (k/fields [:dashboard_id]) (k/modifier "DISTINCT") (k/where (or (= :row nil) (= :col nil))))]
(when (not-empty bad-dashboards)
(log/info "Looks like we need to fix unpositioned cards in these dashboards:" (mapv :dashboard_id bad-dashboards))
;; we are going to take the easy way out, which is to put bad-cards at the bottom of the dashboard
(doseq [{dash-to-fix :dashboard_id} bad-dashboards]
(let [max-row (or (:row (first (k/select DashboardCard (k/aggregate (max :row) :row) (k/where {:dashboard_id dash-to-fix})))) 0)
max-size (or (:size (first (k/select DashboardCard (k/aggregate (max :sizeY) :size) (k/where {:dashboard_id dash-to-fix, :row max-row})))) 0)
max-y (+ max-row max-size)
bad-cards (k/select DashboardCard (k/fields :id :sizeY) (k/where {:dashboard_id dash-to-fix}) (k/where (or (= :row nil) (= :col nil))))]
(loop [[bad-card & rest] bad-cards
row-target max-y]
(k/update DashboardCard
(k/set-fields {:row row-target
:col 0})
(k/where {:id (:id bad-card)}))
(when rest (recur rest (+ row-target (:sizeY bad-card))))))))))
(when-let [bad-dashboards (not-empty (k/select DashboardCard (k/fields [:dashboard_id]) (k/modifier "DISTINCT") (k/where (or (= :row nil) (= :col nil)))))]
(log/info "Looks like we need to fix unpositioned cards in these dashboards:" (mapv :dashboard_id bad-dashboards))
;; we are going to take the easy way out, which is to put bad-cards at the bottom of the dashboard
(doseq [{dash-to-fix :dashboard_id} bad-dashboards]
(let [max-row (or (:row (first (k/select DashboardCard (k/aggregate (max :row) :row) (k/where {:dashboard_id dash-to-fix})))) 0)
max-size (or (:size (first (k/select DashboardCard (k/aggregate (max :sizeY) :size) (k/where {:dashboard_id dash-to-fix, :row max-row})))) 0)
max-y (+ max-row max-size)
bad-cards (k/select DashboardCard (k/fields :id :sizeY) (k/where {:dashboard_id dash-to-fix}) (k/where (or (= :row nil) (= :col nil))))]
(loop [[bad-card & more] bad-cards
row-target max-y]
(k/update DashboardCard
(k/set-fields {:row row-target
:col 0})
(k/where {:id (:id bad-card)}))
(when more
(recur more (+ row-target (:sizeY bad-card)))))))))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment