Passed
Push — master ( 3de881...c52af4 )
by Lucas
43s
created

???.toggle   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
c 1
b 0
f 0
nc 6
dl 0
loc 20
rs 8.8571
nop 0
1
'use babel';
2
3
4
import DevmindBeautifierView from './devmind-beautifier-view';
5
import { CompositeDisposable } from 'atom';
6
7
export default {
8
9
10
  devmindBeautifierView: null,
11
  modalPanel: null,
12
  subscriptions: null,
13
14
  activate(state) {
15
    this.devmindBeautifierView = new DevmindBeautifierView(state.devmindBeautifierViewState);
16
    this.modalPanel = atom.workspace.addModalPanel({
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
17
      item: this.devmindBeautifierView.getElement(),
18
      visible: false
19
    });
20
21
    // Events subscribed to in atom's system can be easily cleaned up with a CompositeDisposable
22
    this.subscriptions = new CompositeDisposable();
23
24
    // Register command that toggles this view
25
    this.subscriptions.add(atom.commands.add('atom-workspace', {
26
      'devmind-beautifier:toggle': () => this.toggle()
27
    }));
28
  },
29
30
  deactivate() {
31
    this.modalPanel.destroy();
32
    this.subscriptions.dispose();
33
    this.devmindBeautifierView.destroy();
34
  },
35
36
  serialize() {
37
    return {
38
      devmindBeautifierViewState: this.devmindBeautifierView.serialize()
39
    };
40
  },
41
42
  toggle() {
43
44
    panel = this;
0 ignored issues
show
Bug introduced by
The variable panel seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.panel.
Loading history...
45
46
    editor = atom.workspace.getActiveTextEditor()
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable editor seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.editor.
Loading history...
47
    text = editor.getText();
0 ignored issues
show
Bug introduced by
The variable text seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.text.
Loading history...
48
    fileName = editor.getTitle();
0 ignored issues
show
Bug introduced by
The variable fileName seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.fileName.
Loading history...
49
    ext = fileName.split('.').pop();
0 ignored issues
show
Bug introduced by
The variable ext seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.ext.
Loading history...
50
      panel.modalPanel.show()
51
      var http = new XMLHttpRequest();
0 ignored issues
show
Bug introduced by
The variable XMLHttpRequest seems to be never declared. If this is a global, consider adding a /** global: XMLHttpRequest */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
52
      var url = "https://beautifier.devmind.io/format";
53
      var params = "extension="+ext+"&content="+text;
54
      http.open("POST", url, true);
55
56
  //Send the proper header information along with the request
57
  http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
58
59
  http.onreadystatechange = function() {//Call a function when the state changes.
60
      if(http.readyState == 4 && http.status == 200) {
61
62
        if(typeof http.responseText.status === "undefined")
63
        {
64
          editor.setText(http.responseText);
65
          atom.notifications.addSuccess('Now your code looks fancy');
0 ignored issues
show
Bug introduced by
The variable atom seems to be never declared. If this is a global, consider adding a /** global: atom */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
66
          panel.modalPanel.hide()
67
        }
68
        else {
69
          atom.notifications.addInfo('File extension not supported. Yet.');
70
        }
71
      }
72
      if(http.status !== 200)
73
      {
74
        console.log(http.status)
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
75
          panel.modalPanel.hide()
76
          atom.notifications.addError('Something went wrong, please check your internet connection');
77
      }
78
  }
79
  http.send(params);
80
    }
81
82
83
84
85
  }
86