diff --git a/app/assets/stylesheets/emails.scss b/app/assets/stylesheets/emails.scss new file mode 100644 index 0000000..98f8a47 --- /dev/null +++ b/app/assets/stylesheets/emails.scss @@ -0,0 +1,20 @@ +// Place all the styles related to the emails controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: https://sass-lang.com/ + +.email_attribute_server { + background-color: cyan; + padding: 1px 2px; +} +.email_attribute_client { + background-color: yellow; + padding: 1px 2px; +} +.email_attribute_ticket { + background-color: orange; + padding: 1px 2px; +} + +.email_content th { + text-align: left; +} diff --git a/app/assets/stylesheets/scaffolds.scss b/app/assets/stylesheets/scaffolds.scss new file mode 100644 index 0000000..bb2597f --- /dev/null +++ b/app/assets/stylesheets/scaffolds.scss @@ -0,0 +1,65 @@ +body { + background-color: #fff; + color: #333; + margin: 33px; } + +body, p, ol, ul, td { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 13px; + line-height: 18px; } + +pre { + background-color: #eee; + padding: 10px; + font-size: 11px; } + +a { + color: #000; } + +a:visited { + color: #666; } + +a:hover { + color: #fff; + background-color: #000; } + +th { + padding-bottom: 5px; } + +td { + padding: 0 5px 7px; } + +div.field, +div.actions { + margin-bottom: 10px; } + +#notice { + color: green; } + +.field_with_errors { + padding: 2px; + background-color: red; + display: table; } + +#error_explanation { + width: 450px; + border: 2px solid red; + padding: 7px 7px 0; + margin-bottom: 20px; + background-color: #f0f0f0; } + +#error_explanation h2 { + text-align: left; + font-weight: bold; + padding: 5px 5px 5px 15px; + font-size: 12px; + margin: -7px -7px 0; + background-color: #c00; + color: #fff; } + +#error_explanation ul li { + font-size: 12px; + list-style: square; } + +label { + display: block; } diff --git a/app/controllers/emails_controller.rb b/app/controllers/emails_controller.rb new file mode 100644 index 0000000..8e3ce4c --- /dev/null +++ b/app/controllers/emails_controller.rb @@ -0,0 +1,82 @@ +class EmailsController < ApplicationController + before_action :set_email, only: [:show, :edit, :update, :destroy] + + # GET /emails + # GET /emails.json + def index + results = email_repository.search({ + query: { + match_all: {} + } + }) + @emails = results.results + end + + # GET /emails/1 + # GET /emails/1.json + def show + end + + # GET /emails/new + def new + @email = Email.new + end + + # GET /emails/1/edit + def edit + end + + # POST /emails + # POST /emails.json + def create + @email = Email.new(email_params) + + respond_to do |format| + if @email.save + format.html { redirect_to @email, notice: 'Email was successfully created.' } + format.json { render :show, status: :created, location: @email } + else + format.html { render :new } + format.json { render json: @email.errors, status: :unprocessable_entity } + end + end + end + + # PATCH/PUT /emails/1 + # PATCH/PUT /emails/1.json + def update + respond_to do |format| + if @email.update(email_params) + format.html { redirect_to @email, notice: 'Email was successfully updated.' } + format.json { render :show, status: :ok, location: @email } + else + format.html { render :edit } + format.json { render json: @email.errors, status: :unprocessable_entity } + end + end + end + + # DELETE /emails/1 + # DELETE /emails/1.json + def destroy + email_repository.delete(params[:id]) + respond_to do |format| + format.html { redirect_to emails_url, notice: 'Email was successfully destroyed.' } + format.json { head :no_content } + end + end + + private + def email_repository + @email_repository ||= EmailRepository.new + end + # Use callbacks to share common setup or constraints between actions. + def set_email + @email = email_repository.find(params[:id]) + end + + # Only allow a list of trusted parameters through. + def email_params + params.fetch(:email, {}) + end +end diff --git a/app/helpers/emails_helper.rb b/app/helpers/emails_helper.rb new file mode 100644 index 0000000..b4dc6ec --- /dev/null +++ b/app/helpers/emails_helper.rb @@ -0,0 +1,2 @@ +module EmailsHelper +end diff --git a/app/models/email.rb b/app/models/email.rb index 611a3ea..f2f3c5c 100644 --- a/app/models/email.rb +++ b/app/models/email.rb @@ -1,7 +1,9 @@ class Email include ActiveModel::Model include ActiveModel::Attributes + include ActiveModel::Conversion + attribute :id attribute :message_id attribute :subject attribute :date, :datetime @@ -28,4 +30,8 @@ class Email def to_hash attributes end + + def persisted? + id.present? + end end diff --git a/app/repositories/email_repository.rb b/app/repositories/email_repository.rb index 7ae438f..06e2f98 100644 --- a/app/repositories/email_repository.rb +++ b/app/repositories/email_repository.rb @@ -28,4 +28,8 @@ class EmailRepository indexes :created_at, type: 'date' indexes :updated_at, type: 'date' end + + def deserialize(document) + Email.new document['_source'].merge('id' => document['_id']) + end end diff --git a/app/views/emails/_email.json.jbuilder b/app/views/emails/_email.json.jbuilder new file mode 100644 index 0000000..a8cc2ec --- /dev/null +++ b/app/views/emails/_email.json.jbuilder @@ -0,0 +1,2 @@ +json.extract! email, :id, :created_at, :updated_at +json.url email_url(email, format: :json) diff --git a/app/views/emails/_form.html.erb b/app/views/emails/_form.html.erb new file mode 100644 index 0000000..0cb69d2 --- /dev/null +++ b/app/views/emails/_form.html.erb @@ -0,0 +1,17 @@ +<%= form_with(model: email) do |form| %> + <% if email.errors.any? %> +
<%= notice %>
+ ++ | ||||
---|---|---|---|---|
<%= email.date %> | +<%= email.subject %> | +<%= link_to 'Show', email %> | +<%= link_to 'Edit', edit_email_path(email) %> | +<%= link_to 'Destroy', email, method: :delete, data: { confirm: 'Are you sure?' } %> | +
<%= notice %>
+ +Date | +<%= @email.date %> | +|
---|---|---|
From | +<%= @email.from.join(', ') %> | +|
To | +<%= @email.to.join(', ') %> | +|
Subject | +<%= @email.subject %> | +|
Clients | ++ <% @email.clients.presence.each do |client| %> + <%= client %> + <% end %> + | +|
Servers | ++ <% @email.servers.presence.each do |server| %> + <%= server %> + <% end %> + | +|
Tickets | ++ <% @email.tickets.presence.each do |ticket| %> + <%= ticket %> + <% end %> + | +|
<%= header["name"] %> | +<%= header["value"] %> | + |
+ <% if @email.plain_body.present? %>
+ <%= @email.plain_body %>+ <% else %> + Empty body + <% end %> + |
+