Skip to content

Instantly share code, notes, and snippets.

View madzhuga's full-sized avatar

Maxim Madzhuga madzhuga

View GitHub Profile
@madzhuga
madzhuga / angular_autocomplete.txt
Created December 16, 2013 09:41
Angular autocomplete with jquery
<div ng-app='MyModule'>
<div ng-controller='DefaultCtrl'>
<input auto-complete ui-items="names" ng-model="selected">
selected = {{selected}}
</div>
</div>
function DefaultCtrl($scope) {
$scope.names = ["john", "bill", "charlie", "robert", "alban", "oscar", "marie", "celine", "brad", "drew", "rebecca", "michel", "francis", "jean", "paul", "pierre", "nicolas", "alfred", "gerard", "louis", "albert", "edouard", "benoit", "guillaume", "nicolas", "joseph"];
}
search_scope = Delivery.accessible_by(current_ability, :read)
search_scope = search_scope.where(state: :quotation_request).
joins(" inner join (select * from (select *, max(id) over (partition by delivery_id) from quotation_requests)t where t.max = t.id)tt on tt.delivery_id = deliveries.id ").
includes(:quotation_requests).
where(quotation_requests: {status: params[:q][:status_in].select(&:present?) })
search_scope = search_scope.search(params[:q])
search_scope = search_scope.order("quotation_requests.id DESC")
set_collection_ivar(search_scope.paginate(page: params[:page], per_page: 20))
@madzhuga
madzhuga / init.rb
Created June 26, 2014 16:00
Sample plugin from red mine
Rails.logger.info 'Starting Example plugin for RedMine'
Redmine::Plugin.register :sample_plugin do
name 'Example plugin'
author 'Author name'
description 'This is a sample plugin for Redmine'
version '0.0.1'
settings :default => {'sample_setting' => 'value', 'foo'=>'bar'}, :partial => 'settings/sample_plugin_settings'
# This plugin adds a project module
this.postNew = function (delivery, tender, success, error) {
var deliveryCopy = angular.copy(delivery);
delete deliveryCopy.state;
var sendPickupRequest = deliveryCopy.sendPickupRequest;
delete deliveryCopy.sendPickupRequest;
....
$http.post('/deliveries.json', {
delivery: deliveryCopy,
@madzhuga
madzhuga / map_directive.js
Created January 12, 2015 18:16
merge result.txt
$scope.addZoomListener = function () {
$scope.zoomListener = google.maps.event.addListener($scope.map, 'zoom_changed', function () {
//when zoom changed we need to clear all old markers
// as it changes regions to their parents etc
$scope.calculatePortInfoPosition();
$scope.cleanAllMarkers();
$scope.reloadMarkers();
});
};
@madzhuga
madzhuga / stock_provisioning.rb
Created February 4, 2015 19:12
Rails Workflow Engine operation template example
module DemoTemplates
class StockProvisioning < Workflow::OperationTemplate
def resolve_dependency operation
resource = operation.data[:resource]
# resource is order.
# for every order line we check if product needs provisioning
# (if it's amount lower that provisioning limit)
resource.order_lines.map(:product).any?{|p| p.need_provisioning? }
end
end
@madzhuga
madzhuga / Gemfile
Created April 5, 2015 18:25
Minimal Rails 4.2 application
source 'https://rubygems.org'
gem 'thin'
gem 'rails', '4.2.0'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
class User < ApplicationRecord
...
after_create :start_newcomer_process
def start_newcomer_process
template = RailsWorkflow::ProcessTemplate.find_by_title('New User Process')
RailsWorkflow::ProcessManager.start_process(
template.id,
{ user: self, url_path: 'user_path', url_params: self }
)
<% if current_operation.present? %>
<h1><%= current_operation.title %></h1>
<% end %>
<h3>User</h3>
<p>Email: <%= @user.email if @user.email %></p>
<% if current_operation.present? %>
<%= link_to 'Complete', user_path(@user), method: :put, class: "btn btn-primary" %>
<% end %>
class UsersController < ApplicationController
...
def update
if current_operation
current_operation.complete
redirect_to users_path
end
end
end