976
977 @doc """
978 Called by escaper at runtime to verify that a value is not nil.
979 """
980 def not_nil!(nil) do
981 raise ArgumentError, "comparison with nil is forbidden as it is unsafe. " <>
982 "If you want to check if a value is nil, use is_nil/1 instead"
983 end
984 def not_nil!(not_nil) do
985 not_nil
986 end
186 # SOUSCATEGORIE
187 # First page
188 def tri_souscategorie(val, id_souscat) do
189 case val do
190 "1" ->
191 from p in Produit,
192 where: p.id_souscat == ^id_souscat,
193 select: p,
194 limit: 15,
195 order_by: [asc: p.id_produit]
196 "2" ->
239 Repo.one(query)
240 end
241
242 # GET 12 PRODUITS
243 def get_produit_limit_twelve_souscategorie(id_souscat, tri) do
244 Repo.all(TriRequette.tri_souscategorie(tri, id_souscat))
245 end
246
247 # GET 12 PRODUITS FROM ID
248 def get_produit_limit_twelve_from_id_next_souscategorie(id_produit, id_souscat, tri) do
249 p = get_produit_by_id_produit(id_produit)
193 produits = ProdRequette.get_produit_limit_twelve_categorie(id_cat, tri)
194 nb_ligne = ProdRequette.count_ligne_produit_categorie(id_cat)
195 {produits, nb_ligne}
196 else
197 id_souscat = SouscatRequette.get_id_souscat_by_nom_souscat(souscat, cat)
198 produits = ProdRequette.get_produit_limit_twelve_souscategorie(id_souscat, tri)
199 nb_ligne = ProdRequette.count_ligne_produit_souscategorie(id_souscat)
200 {produits, nb_ligne}
201 end
202 end
203 else
7 alias Bebemayotte.PanierRequette
8
9 def mount(_params, %{"id_session" => session,"user" => user,"cat" => cat, "souscat" => souscat,"list_panier" => list_panier, "search" => search}, socket) do
10 categories = CatRequette.get_all_categorie()
11 souscategories = SouscatRequette.get_all_souscategorie()
12 {produits, nb_ligne} = filtre(cat, souscat, search, "1")
13 nb_total = produits |> Enum.count()
14 {first_row_id, last_row_id} = if_vide_produits(produits, nb_total)
15 nb_page = nb_ligne |> nombre_page()
16 SyncDb.subscribe()
17
315 [:phoenix, :live_view, :mount],
316 %{socket: socket, params: params, session: session},
317 fn ->
318 socket =
319 params
320 |> view.mount(session, socket)
321 |> handle_mount_result!({:mount, 3, view})
322
323 {socket, %{socket: socket, params: params, session: session}}
324 end
325 )
267span(EventPrefix, StartMetadata, SpanFunction) ->
268 StartTime = erlang:monotonic_time(),
269 DefaultCtx = erlang:make_ref(),
270 execute(EventPrefix ++ [start], #{system_time => erlang:system_time()}, merge_ctx(StartMetadata, DefaultCtx)),
271
272 try {_, #{}} = SpanFunction() of
273 {Result, StopMetadata} ->
274 execute(EventPrefix ++ [stop], #{duration => erlang:monotonic_time() - StartTime}, merge_ctx(StopMetadata, DefaultCtx)),
275 Result
276 catch
277 ?WITH_STACKTRACE(Class, Reason, Stacktrace)
311
312 defp call_mount_and_handle_params!(socket, view, session, params, uri) do
313 mount_params = if socket.router, do: params, else: :not_mounted_at_router
314
315 socket
316 |> Utils.maybe_call_live_view_mount!(view, mount_params, session)
317 |> mount_handle_params(view, params, uri)
318 |> case do
319 {:noreply, %Socket{redirected: {:live, _, _}} = socket} ->
320 {:stop, socket}
321
127 action,
128 flash,
129 host_uri
130 )
131
132 case call_mount_and_handle_params!(socket, view, mount_session, conn.params, request_url) do
133 {:ok, socket} ->
134 data_attrs = [
135 phx_view: config.name,
136 phx_session: sign_root_session(socket, router, view, to_sign_session),
137 phx_static: sign_static_token(socket)
30 end
31 end
32
33 """
34 def live_render(%Plug.Conn{} = conn, view, opts \\ []) do
35 case LiveView.Static.render(conn, view, opts) do
36 {:ok, content, socket_assigns} ->
37 conn
38 |> Phoenix.Controller.put_view(LiveView.Static)
39 |> LiveView.Plug.put_cache_headers()
40 |> Phoenix.Controller.render(
1defmodule BebemayotteWeb.PageController do
2 use BebemayotteWeb, :controller
3
4 alias Phoenix.LiveView
5 alias Bebemayotte.CatRequette
6 alias Bebemayotte.ProdRequette
1defmodule BebemayotteWeb.PageController do
2 use BebemayotteWeb, :controller
3
4 alias Phoenix.LiveView
5 alias Bebemayotte.CatRequette
6 alias Bebemayotte.ProdRequette
347 case pipeline.(conn) do
348 %Plug.Conn{halted: true} = halted_conn ->
349 halted_conn
350 %Plug.Conn{} = piped_conn ->
351 try do
352 plug.call(piped_conn, plug.init(opts))
353 else
354 conn ->
355 duration = System.monotonic_time() - start
356 metadata = %{metadata | conn: conn}
357 :telemetry.execute([:phoenix, :router_dispatch, :stop], %{duration: duration}, metadata)
1defmodule BebemayotteWeb.Endpoint do
2 use Phoenix.Endpoint, otp_app: :bebemayotte
3
4 # The session will be stored in the cookie and signed,
5 # this means its contents can be read but not tampered with.
6 # Set :encryption_salt if you would also like to encrypt it.
1defmodule BebemayotteWeb.Endpoint do
2 use Phoenix.Endpoint, otp_app: :bebemayotte
3
4 # The session will be stored in the cookie and signed,
5 # this means its contents can be read but not tampered with.
6 # Set :encryption_salt if you would also like to encrypt it.
60
61 {:plug, conn, handler, opts} ->
62 %{adapter: {@connection, req}} =
63 conn =
64 conn
65 |> handler.call(opts)
66 |> maybe_send(handler)
67
68 :telemetry.execute(
69 [:plug_adapter, :call, :stop],
70 %{duration: System.monotonic_time() - start},
32-optional_callbacks([terminate/3]).
33
34-spec execute(Req, Env) -> {ok, Req, Env}
35 when Req::cowboy_req:req(), Env::cowboy_middleware:env().
36execute(Req, Env=#{handler := Handler, handler_opts := HandlerOpts}) ->
37 try Handler:init(Req, HandlerOpts) of
38 {ok, Req2, State} ->
39 Result = terminate(normal, Req2, State, Handler),
40 {ok, Req2, Env#{result => Result}};
41 {Mod, Req2, State} ->
42 Mod:upgrade(Req2, Env, Handler, State);
301 end.
302
303execute(_, _, []) ->
304 ok;
305execute(Req, Env, [Middleware|Tail]) ->
306 case Middleware:execute(Req, Env) of
307 {ok, Req2, Env2} ->
308 execute(Req2, Env2, Tail);
309 {suspend, Module, Function, Args} ->
310 proc_lib:hibernate(?MODULE, resume, [Env, Tail, Module, Function, Args]);
311 {stop, _Req2} ->
290%% to simplify the debugging of errors. The proc_lib library
291%% already adds the stacktrace to other types of exceptions.
292-spec request_process(cowboy_req:req(), cowboy_middleware:env(), [module()]) -> ok.
293request_process(Req, Env, Middlewares) ->
294 try
295 execute(Req, Env, Middlewares)
296 catch
297 exit:Reason={shutdown, _}:Stacktrace ->
298 erlang:raise(exit, Reason, Stacktrace);
299 exit:Reason:Stacktrace when Reason =/= normal, Reason =/= shutdown ->
300 erlang:raise(exit, {Reason, Stacktrace}, Stacktrace)