 (ns webapp.framework.client.components.admin
   (:require
-   [webapp.framework.client.coreclient   :as c :include-macros true])
-
-
-	(:use
-		[webapp.framework.client.system-globals  :only  [
-																										 client-data-windows
-																										 client-query-cache
-																										 ]]))
+    [webapp.framework.client.coreclient   :as c :include-macros true])
+
+
+  (:use
+    [webapp.framework.client.system-globals  :only  [
+                                                      client-data-windows
+                                                      client-query-cache
+                                                      client-record-cache
+                                                      ]]))
 (c/ns-coils 'webapp.framework.client.components.admin)
 
 

(c/defn-ui-component     admin-view-list-data-sources   [data-sources]

  (let [
        use-source    (c/read-ui data-sources [:data-source])
	    	view          (c/read-ui data-sources [:data-view])
	    	]

	(c/div nil
		   (c/map-many
			#(c/container

			  (let [table-name   (str (name  (-> (second %) :def :table)))
					data-source  (first %)]

				(if (or (nil? use-source)
						(= use-source  data-source))

				  (c/div {:style {:color  "black"}}
						 (c/inline "300px" (c/div nil table-name))
						 (c/inline "100px" (c/div {:style {:fontSize "12px" :padding "7px"}
												   :onClick
												   (fn [e] (do
															 (c/write-ui
															  data-sources
															  [:data-source]
															  data-source)

															 (c/write-ui
															  data-sources
															  [:data-view]
															  "defn")
															 ))} "Defn"))
						 (c/inline "100px" (c/div {:style {:fontSize "12px" :padding "7px"}
												   :onClick
												   (fn [e] (do
															 (c/write-ui
															  data-sources
															  [:data-source]
															  data-source)

															 (c/write-ui
															  data-sources
															  [:data-view]
															  "data")
															 ))
												   } "Data"))

						 ))))
			(c/read-ui data-sources [:values])
			)
            (cond
			 (and use-source (= view "defn"))

			  (c/component admin-view-show-data-source-def
						   (c/read-ui data-sources
									 [:values (keyword use-source) :def]) [])

			 (and use-source (= view "data"))

			  (c/component admin-view-show-data-source-data
						   (c/read-ui data-sources
									 [:values (keyword use-source) :data]) []))

         (c/div nil "List of data sources")

         )))







(c/defn-ui-component
  admin-view-show-data-source-data   [table-name]
  (let [table             table-name
        table-data       (keys @(get @(get @client-record-cache table) :values) )
                            ]
    (c/container
      nil


      (c/div {:style {:color  "blue"}}
             (c/container
               (c/inline "50%" (c/text (str "count" )))
               (c/inline "50%" (c/text (count aaa)))
               )
      (c/div nil (str "table-data: " table-data))
             ))))



