Skip to content

Commit

Permalink
Remove CoffeeScript (#53)
Browse files Browse the repository at this point in the history
* remove coffee

* fix string issue in app.json

* conditional airbrake

* .js instead of .js.js

* add closure

* schema load & seed instead of setup

* rename more .js.js

* add closures to js files

* remove obscure code
  • Loading branch information
patrickdet committed May 14, 2018
1 parent cbe2565 commit 49a6787
Show file tree
Hide file tree
Showing 46 changed files with 1,114 additions and 805 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ gem 'dotiw'

# Moment.js lib
gem 'momentjs-rails'
gem 'coffee-rails'

group :development do
gem 'quiet_assets'
Expand Down
8 changes: 0 additions & 8 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -172,13 +172,6 @@ GEM
coderay (1.1.1)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (4.1.1)
coffee-script (>= 2.2.0)
railties (>= 4.0.0, < 5.1.x)
coffee-script (2.4.1)
coffee-script-source
execjs
coffee-script-source (1.10.0)
concurrent-ruby (1.0.5)
contact_us (1.0.1)
rails (>= 4.2.0)
Expand Down Expand Up @@ -413,7 +406,6 @@ DEPENDENCIES
bundler
cancancan!
chartkick!
coffee-rails
contact_us (~> 1.0.1)
datetimepicker-rails!
dotenv
Expand Down
2 changes: 1 addition & 1 deletion app.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zeitkit",
"scripts": {
"postdeploy": "rake db:setup"
"postdeploy": "rake db:schema:load && rake db:seed"
},
"env": {
"MAILER_ADDRESS": {
Expand Down
90 changes: 90 additions & 0 deletions app/assets/javascripts/angular/directives/auto_grow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
(function() {
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
/**
The MIT License (MIT)
Copyright (c) 2013 Thom Seddon
Copyright (c) 2010 Google
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
Adapted from: http://code.google.com/p/gaequery/source/browse/trunk/src/static/scripts/jquery.autogrow-textarea.js
Works nicely with the following styles:
textarea {
resize: none;
word-wrap: break-word;
transition: 0.05s;
-moz-transition: 0.05s;
-webkit-transition: 0.05s;
-o-transition: 0.05s;
}
Usage: <textarea auto-grow></textarea>
*/

const app = angular.module('app');
app.directive('autoGrow', () =>
function(scope, element, attr) {
const minHeight = element[0].offsetHeight;
const paddingLeft = element.css('paddingLeft');
const paddingRight = element.css('paddingRight');
const $shadow = angular.element('<div></div>').css({
position: 'absolute',
top: -10000,
left: -10000,
width: element[0].offsetWidth - parseInt(paddingLeft || 0) - parseInt(paddingRight || 0),
fontSize: element.css('fontSize'),
fontFamily: element.css('fontFamily'),
lineHeight: element.css('lineHeight'),
resize: 'none',
});
angular.element(document.body).append($shadow);
const update = function() {
const times = function(string, number) {
let i = 0;
let r = '';

while (i < number) {
r += string;
i++;
}
return r;
};

const val = element.val()
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/&/g, '&amp;')
.replace(/\n$/, '<br/>&nbsp;')
.replace(/\n/g, '<br/>')
.replace(/\s{2,}/g, space => times('&nbsp;', space.length - 1) + ' ');
$shadow.html(val);
element.css('height', Math.max($shadow[0].offsetHeight + 10, minHeight) + 'px'); // the "threshold"
};

element.bind('keyup keydown keypress change', update);
update();
},
);
})();
77 changes: 0 additions & 77 deletions app/assets/javascripts/angular/directives/auto_grow.js.coffee

This file was deleted.

18 changes: 18 additions & 0 deletions app/assets/javascripts/angular/directives/ng_enter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
(function() {
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const app = angular.module('app');

app.directive('ngEnter', () =>
(scope, element, attrs) =>
element.bind('keydown keypress', function(event) {
if (event.which === 13) {
scope.$apply(() => scope.$eval(attrs.ngEnter));
return event.preventDefault();
}
}),
);
}());
9 changes: 0 additions & 9 deletions app/assets/javascripts/angular/directives/ng_enter.js.coffee

This file was deleted.

72 changes: 72 additions & 0 deletions app/assets/javascripts/angular/notifier/notifier.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
(function() {
/*
* decaffeinate suggestions:
* DS102: Remove unnecessary code created because of implicit returns
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const app = angular.module("app");

app.factory("UiNotifier", function() {
class UiNotifier {
success(text) {
return $(".top-right").notify({
message: {
html: text
},
type: "success"
}).show();
}

error(text) {
return $(".top-right").notify({
message: {
html: text
},
type: "error"
}).show();
}

hide() {
return $(".top-right div")
.css({transition: "opacity 0.3s"})
.css({opacity: 0})
.css({transition: ""});
}

render_error_array(arr, prefix_msg) {
if (prefix_msg == null) {
prefix_msg = "Folgende Fehler sind aufgetreten: ";
}
const error_html = window.App.Errors.arr_to_html(arr);
const prefixed = `${prefix_msg}${error_html}`;
return this.error(prefixed);
}

errors_or_fallback(data, fallback) {
if (fallback == null) {
fallback = "Ein unbekannter Fehler is aufgetreten";
}
if (data && data.errors) {
return this.render_error_array(data.errors);
} else {
return this.error("Unbekannter Fehler beim Request aufgetreten.");
}
}

errors_from_xhr(xhr, base_message) {
let error_html = base_message;
if (xhr && xhr.responseJSON && xhr.responseJSON.errors) {
error_html += ` ${window.App.Errors.arr_to_html(xhr.responseJSON.errors)}`;
}
return error_html;
}

loading_message() {
return this.success("<i class='icon-spinner icon-spin'></i> Lade...");
}
}

return UiNotifier;
});
})();
44 changes: 0 additions & 44 deletions app/assets/javascripts/angular/notifier/notifier.js.coffee

This file was deleted.

43 changes: 43 additions & 0 deletions app/assets/javascripts/angular/worklogs/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
(function() {
/*
* decaffeinate suggestions:
* DS001: Remove Babel/TypeScript constructor workaround
* DS102: Remove unnecessary code created because of implicit returns
* DS206: Consider reworking classes to avoid initClass
* DS207: Consider shorter variations of null checks
* Full docs: https://github.com/decaffeinate/decaffeinate/blob/master/docs/suggestions.md
*/
const app = angular.module("app");

app.factory("Client", ["RailsResource", function(RailsResource){
class Client extends RailsResource {
static initClass() {
this.configure({url: '/clients', name: 'client'});
}
constructor(opts){
super();
if (opts == null) { opts = {}; }
const defaultOpts = {
hourly_rate_cents: 0,
shared: false,
companyName: "",
name: ""
};
const _this = this;
const useOpts = _.extend(defaultOpts, opts);
_.each(useOpts, (val, key) => _this[key] = val);
}

nameOrCompanyName() {
if (this.name.length) {
return `${this.name} [${this.user.username}]`;
} else {
return `${this.companyName} [${this.user.username}]`;
}
}
}
Client.initClass();
return Client;
}
]);
})();
Loading

0 comments on commit 49a6787

Please sign in to comment.