hydrooj-addons-manager 0.1.2 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.ts CHANGED
@@ -43,9 +43,11 @@ class AddonsManagerHandler extends Handler {
43
43
  for(const pkg of packages){
44
44
  if(checkPackageIsLocal(pkg)) lockedPackages.push(pkg);
45
45
  }
46
+ console.log(this.request);
46
47
  this.response.body = this.request.body ||{
47
48
  packages: packages,
48
49
  lockedPackages: lockedPackages,
50
+ success: null,
49
51
  result: null
50
52
  };
51
53
  this.renderHTML(this.response.template, {title: 'manage_addons'});
@@ -53,7 +55,7 @@ class AddonsManagerHandler extends Handler {
53
55
  async post()
54
56
  {
55
57
  const body = this.request.body;
56
- const packages = await AddonsManagerHandler.model.getActivedPackages();
58
+ let packages = await AddonsManagerHandler.model.getActivedPackages();
57
59
  let lockedPackages = await AddonsManagerHandler.model.getLockedPackages();
58
60
  for(const pkg of packages){
59
61
  if(checkPackageIsLocal(pkg)) lockedPackages.push(pkg);
@@ -92,11 +94,23 @@ class AddonsManagerHandler extends Handler {
92
94
 
93
95
  // optional: better log formatting
94
96
  console.log(`[Addons Manager] Action=${pkg.action} Package=${pkg.name} Version=${pkg.version} Result=${JSON.stringify(result)}`);
95
- this.back({
96
- result: result,
97
- packages: packages,
98
- lockedPackages: lockedPackages
99
- });
97
+ if(result.success){
98
+ packages = await AddonsManagerHandler.model.getActivedPackages();
99
+ lockedPackages = await AddonsManagerHandler.model.getLockedPackages();
100
+ this.response.template = 'manage_addons.html';
101
+ for(const pkg of packages){
102
+ if(checkPackageIsLocal(pkg)) lockedPackages.push(pkg);
103
+ }
104
+ this.response.body = {
105
+ packages: packages,
106
+ lockedPackages: lockedPackages,
107
+ success: result.success,
108
+ result: result.message || 'Operation successful'
109
+ };
110
+ this.renderHTML(this.response.template, {title: 'manage_addons'});
111
+ }else {
112
+ throw new UserFacingError(result.message || 'Operation failed');
113
+ }
100
114
  }
101
115
  }
102
116
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hydrooj-addons-manager",
3
- "version": "0.1.2",
3
+ "version": "0.1.5",
4
4
  "description": "addons manager for hydrooj",
5
5
  "main": "index.ts",
6
6
  "author": "https://github.com/Bryan0324",
@@ -127,18 +127,17 @@
127
127
  <button type="submit" name="action" value="add" class="btn btn--primary">{{ _('activate') }}</button>
128
128
  </div>
129
129
  </form>
130
- {% if result %}
131
- {% if result.success %}
132
- <div class="alert alert--success">
133
- {{ result.success }}
134
- </div>
135
- {% else %}
136
- <div class="alert alert--danger">
137
- {{ result.error }}
138
- </div>
139
- {% endif %}
140
- {% endif %}
141
130
  </div>
142
131
  </div>
143
132
  </div>
133
+ <script>
134
+ const result = {{ result | dump | safe }};
135
+ console.log('Debug: ', result);
136
+ </script>
137
+ {% if success and result %}
138
+ <script>
139
+ const message = {{ result | dump | safe }};
140
+ alert('✓ success: ' + message);
141
+ </script>
142
+ {% endif %}
144
143
  {% endblock %}