Last active
July 13, 2023 17:41
-
-
Save pazteddy/a13ce9ee6d919b844a09496f84d9cb10 to your computer and use it in GitHub Desktop.
Snippets of code to develop a little faster the Offix workshop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <body> | |
| <header> | |
| <div class="container"> | |
| <div class="header navbar"> | |
| <%=link_to image_tag("/images/logo.png"), departments_path%> | |
| <%=form_with url: "/search", method: :get do |f|%> | |
| <%=f.label :consulta, "Search employees: " %> | |
| <%=f.text_field :consulta %> | |
| <%end%> | |
| </div> | |
| </div> | |
| </header> | |
| <%= yield %> | |
| <footer class="footer footer__content">© 2022 - Offix</footer> | |
| </body> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%=form_with model: department, class: "flex flex-column gap-4 mb-4" do |form|%> | |
| <div class="input"> | |
| <%=form.label :name, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=form.text_field :name, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div class="input"> | |
| <%=form.label :description, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=form.text_area :description, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div> | |
| <%=form.label :cover, class: "content-xs overline"%> | |
| <div> | |
| <%=form.file_field :cover, accept: "image/png, image/jpeg"%> | |
| </div> | |
| </div> | |
| <%=form.submit class: "button button--secondary"%> | |
| <%end%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section class="section"> | |
| <div class="container"> | |
| <h1 class="heading mb-4">New Department</h1> | |
| <%=render "form", department: @department%> | |
| <%=link_to "Back", departments_path, class: "button button--subtle"%> | |
| </div> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section class="section"> | |
| <div class="container"> | |
| <h1 class="heading mb-4"><%[email protected]%></h1> | |
| <p class="mb-4"><%[email protected]%></p> | |
| <h2 class="heading--sm mb-4">Employees</h2> | |
| <%=link_to "New employee", new_employee_path(department_id: @department.id), class: "button button--secondary mb-4"%> | |
| <div class="flex flex-column gap-4"> | |
| <%@employees.each do |employee|%> | |
| <div class="employee-card"> | |
| <div class="employee-card__header"> | |
| <%=image_tag employee.avatar.attached? ? employee.avatar : "/images/avatar_user.png", | |
| class: "employee-card__avatar" %> | |
| <div class="employee-card__details"> | |
| <p class="heading--xs"><%=employee.name%></p> | |
| <p class="content-sm"><%=employee.role%></p> | |
| </div> | |
| </div> | |
| <div class="employee-card__footer"> | |
| <%=link_to "Edit"%> | |
| <%=link_to "Destroy"%> | |
| </div> | |
| </div> | |
| <%end%> | |
| </div> | |
| <%=link_to "Back to departments", departments_path%> | |
| </div> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <%=form_with model: employee, class: "flex flex-column gap-4 mb-4" do |f|%> | |
| <div class="input"> | |
| <%=f.label :name, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=f.text_field :name, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div class="input"> | |
| <%=f.label :nationality, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=f.text_field :nationality, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div class="input"> | |
| <%=f.label :role, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=f.text_field :role, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div class="input"> | |
| <%=f.label :birth_date, class: "content-xs overline"%> | |
| <div class="input__container"> | |
| <%=f.date_field :birth_date, class: "input__content"%> | |
| </div> | |
| </div> | |
| <div class="select"> | |
| <%=f.label :department_id, class: "content-xs overline"%> | |
| <%= f.collection_select :department_id, Department.order(:name), :id, :name, { selected: department.id }, class: "select__input" %> | |
| </div> | |
| <div> | |
| <%=f.label :avatar, class: "content-xs overline"%> | |
| <div> | |
| <%=f.file_field :avatar, accept: "image/png, image/jpeg"%> | |
| </div> | |
| </div> | |
| <%=f.submit class: "button button--secondary"%> | |
| <%end%> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section class="section"> | |
| <div class="container"> | |
| <h1 class="heading mb-4">New Employee</h1> | |
| <%=render "form", employee: @employee, department: @department%> | |
| <%=link_to "Back", department_path(@department), class: "button button--subtle"%> | |
| </div> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section class="section"> | |
| <div class="container"> | |
| <h1 class="heading">Search results</h1> | |
| <ul> | |
| <%@employees.each do |employee|%> | |
| <li><%=employee.name%></li> | |
| <%end%> | |
| </ul> | |
| </div> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <section class="section"> | |
| <div class="container"> | |
| <h1 class="heading mb-4">Search results</h1> | |
| <p>Search term:"<%= @query %>"</p> | |
| <p><%[email protected]%> employees found</p> | |
| <div class="flex flex-column gap-4"> | |
| <%@employees.each do |employee|%> | |
| <div class="employee-card"> | |
| <div class="employee-card__header"> | |
| <%=image_tag employee.avatar.attached? ? employee.avatar : "/images/avatar_user.png", | |
| class: "employee-card__avatar" %> | |
| <div class="employee-card__details"> | |
| <p class="heading--xs"><%=employee.name%></p> | |
| <p class="content-sm"><%=employee.role%></p> | |
| </div> | |
| </div> | |
| <div class="employee-card__footer"> | |
| <%=link_to "Edit", edit_employee_path(employee)%> | |
| <%=link_to "Destroy", employee_path(employee), data: { turbo_method: :delete, turbo_confirm: "Seguro de borrar el empleado?"} %> | |
| </div> | |
| </div> | |
| <%end%> | |
| </div> | |
| </section> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| puts "Seeding DB" | |
| Employee.destroy_all | |
| Department.destroy_all | |
| engineering = Department.create(name: "Engineering", | |
| description: "This is a great department") | |
| marketing = Department.create(name: "Marketing", | |
| description: "This is a great department") | |
| operations = Department.create(name: "Operations", | |
| description: "This is a great department") | |
| Employee.create(name: "Emmet Bart", | |
| role: "Software Developer", | |
| department: engineering, | |
| nationality: "Peru", | |
| birth_date: 31.years.ago) | |
| Employee.create(name: "Alva Galia", | |
| role: "Senior Software Developer", | |
| department: engineering, | |
| nationality: "Mexico", | |
| birth_date: 35.years.ago) | |
| Employee.create(name: "Rico Cornelius", | |
| role: "Apprentice", | |
| department: engineering, | |
| nationality: "Peru", | |
| birth_date: 21.years.ago) | |
| Employee.create(name: "Mario Testino", | |
| role: "Manager", | |
| department: marketing, | |
| nationality: "Bolivia", | |
| birth_date: 30.years.ago) | |
| Employee.create(name: "Testino Diprueba", | |
| role: "Social Media Creator", | |
| department: marketing, | |
| nationality: "Peru", | |
| birth_date: 25.years.ago) | |
| Employee.create(name: "John Doe", | |
| role: "Operation Manager", | |
| department: operations, | |
| nationality: "Peru", | |
| birth_date: 38.years.ago) | |
| Employee.create(name: "Johana Doe", | |
| role: "Logistic Supervisor", | |
| department: operations, | |
| nationality: "Bolivia", | |
| birth_date: 27.years.ago) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment